awk print variable on a new line 
Author Message
 awk print variable on a new line

Hello i have a file with ip address

192.168.0.1,192.168.38.8,192.168.37.77 ... etc

how can i print each variable on a new line by itself ....

plz advise ....

-chris



Mon, 15 Nov 2004 01:27:47 GMT  
 awk print variable on a new line
tr "," "\n" <infile >outfile
Quote:

> Hello i have a file with ip address

> 192.168.0.1,192.168.38.8,192.168.37.77 ... etc

> how can i print each variable on a new line by itself ....

> plz advise ....

> -chris



Mon, 15 Nov 2004 02:20:11 GMT  
 awk print variable on a new line

Quote:

>Hello i have a file with ip address

>192.168.0.1,192.168.38.8,192.168.37.77 ... etc

>how can i print each variable on a new line by itself ....

If you really want an awk solution,

awk '{print}' RS="," infile > outfile



Mon, 15 Nov 2004 03:00:20 GMT  
 awk print variable on a new line
Under gawk on W98
    awk 1 RS=,<i>o
Your shell may require additional whitespace and quotes.

I like that "1" is a meaningful program in awk.  Are there any other
languages that yeild useful results (with or without set-up like the RS
assignment) off of one-symbol (or even one bit) programs?  "1" isn't even a
valid statement in C without a semicolon--much less a program; and "1" in
APL does make the workspace display "1"...any others?

    - Dan


Quote:
> Hello i have a file with ip address

> 192.168.0.1,192.168.38.8,192.168.37.77 ... etc

> how can i print each variable on a new line by itself ....

> plz advise ....

> -chris



Mon, 15 Nov 2004 11:41:10 GMT  
 awk print variable on a new line

% Hello i have a file with ip address
%
% 192.168.0.1,192.168.38.8,192.168.37.77 ... etc
%
% how can i print each variable on a new line by itself ....

The data is separated by commas, so you need to specify that the
comma is the field separator, then you need to iterate
over the fields and print each of them. Here's one way:

  awk -F, '{ for (i = 1; i <= NF; i++) print $i }' file > output

You could also perform a global replace of commas with new-lines:

  awk '{ gsub(/,/, "\n"); print }' file > output

--

Patrick TJ McPhee
East York  Canada



Mon, 15 Nov 2004 12:01:52 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. awk won't print multiple lines

2. Print NUM lines of trailing context with awk?

3. Passing command line variables to AWK in shell script

4. Awk Command-line Variables - Thanks!

5. Awk Command-Line Variables

6. Command line variable assignment in awk

7. print several variables with awk

8. how to print a shell variable in awk states

9. accessing a shell variable in an awk print statement

10. AWK print variable

11. redirecting print output to variable name in awk

12. how to split each new line into a list, considering quoted new line characters

 

 
Powered by phpBB® Forum Software