grep/awk/sed question

grep/awk/sed question

Post by Ed_Ze » Thu, 22 Jun 2006 00:01:30



Can someone help with this what should be a straightforward question
yet I can't find the answer to:

I need to read a list of files that contain a username (the text after
"Username: ") and output that to another file.

The idea is that I can have a list of who ran the resultant output
files so it looks like this:

<name of file>
username
<name of file>
username

What's the best way of doing this?

Many thanks,

Ed.

 
 
 

grep/awk/sed question

Post by Steven Din » Thu, 22 Jun 2006 00:09:13



> Can someone help with this what should be a straightforward question
> yet I can't find the answer to:

> I need to read a list of files that contain a username (the text after
> "Username: ") and output that to another file.

> The idea is that I can have a list of who ran the resultant output
> files so it looks like this:

> <name of file>
> username
> <name of file>
> username

> What's the best way of doing this?

> Many thanks,

> Ed.

Try:

grep "Username: " * | sed 's/:Username: /\n/' > list.txt

--
Steven Ding
Email: wjding<at>gmail.com

 
 
 

grep/awk/sed question

Post by Ed_Ze » Thu, 22 Jun 2006 00:17:32


That looks good.

Thanks for the quick reply.

Ed.



> > Can someone help with this what should be a straightforward question
> > yet I can't find the answer to:

> > I need to read a list of files that contain a username (the text after
> > "Username: ") and output that to another file.

> > The idea is that I can have a list of who ran the resultant output
> > files so it looks like this:

> > <name of file>
> > username
> > <name of file>
> > username

> > What's the best way of doing this?

> > Many thanks,

> > Ed.

> Try:

> grep "Username: " * | sed 's/:Username: /\n/' > list.txt

> --
> Steven Ding
> Email: wjding<at>gmail.com

 
 
 

grep/awk/sed question

Post by Stephane Chazela » Thu, 22 Jun 2006 00:24:32


[...]

Quote:> grep "Username: " * | sed 's/:Username: /\n/' > list.txt

Note that the Unix syntax is:

grep "Username: " -- * | sed 's/:Username: /\
/' > list.txt

Note that the above fails if some files have "Username: " in
their name.

Another alternative:

awk '
  /^Username: / {
    print substr(FILENAME, 3)
    print substr($0, 11)
  }' ./*

--
Stephane

 
 
 

grep/awk/sed question

Post by Ed Morto » Thu, 22 Jun 2006 07:53:06



> Can someone help with this what should be a straightforward question
> yet I can't find the answer to:

> I need to read a list of files that contain a username (the text after
> "Username: ") and output that to another file.

> The idea is that I can have a list of who ran the resultant output
> files so it looks like this:

> <name of file>
> username
> <name of file>
> username

> What's the best way of doing this?

> Many thanks,

> Ed.

Depending on how spaces appear in your input files, this may be all you
need:

awk '/Username: /{ printf "%s\n%s\n", FILENAME, $NF }' *

Regards,

        Ed.

 
 
 

1. newbie grep/sed/awk and hd questions

My system is a SCO Openserver 5.0.4
I have the following questions:
1. How can I grep a string and delete it from the text file when found
using the above utilities?
2. How do I delete a first fixed length string from a text file? for
example
I want to delete 01C00FFFF from
01C00FFFF07E3018C003400FFFF07758306006880827704B6C20201D800BE7701B44202022C80BEB7
3. how can I obtain only the HEX part from the hd (hex dump) utility?
I tried  "hd -bx > output" but it also gave me the OFFSET value.

Thanks in advance,
Chacrint
Chacrint

2. gopher+1.2b4 patches uploaded

3. Quick bash shell script awk, sed, grep question

4. TV Tuner Card Recommendation

5. (awk) vs. (grep|awk) efficiency question

6. USB and Swedish characters

7. Grep/awk/sed for multiple/groups of lines in a file???

8. port tunneling problem with gaim

9. grep, awk, or sed for an unwieldy file

10. Complied Binaries of GNU versions of awk, sed and grep for Solaris 2.6

11. tar, grep, sed, awk for MS-DOS ?

12. Grep/awk/sed for multiple/groups of lines in a file???

13. HELP....using sed, awk or grep...