Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change to line format

Status
Not open for further replies.

driddickemc

IS-IT--Management
May 3, 2004
42
US
Have a text file..e.g

700
873
444
334
259
399

Want to change to

700, 873,444,334,259,399

Any help please here..not a scripting guru..but trying to change this file..

Thanks
 
either:
tr '\n' ',' < file

OR

nawk -v ORS=',' '1' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
d@home-laptop /c/emc/quest
$ tr '\n'',' < edidevs.txt
tr: two strings must be given when translating

pay attention to my original post.
'\n' and ',' are separated by space

d@home-laptop /c/emc/quest
$ nawk
bash: nawk: command not found

d@home-laptop /c/emc/quest
$ awk -v ORS=',''1' edidevs.txt
awk: edidevs.txt
awk: ^ syntax error

same comment as above



vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks guy's for the help.. ultimately used futurelet's awk command..works great. . Can you break this down to me. I would like to know what this does.

Thanks
Dennis-
 
[tt]ORS[/tt] is the Output-Recod-Separator, what awk puts after every string that you [tt]print[/tt]; normally, it's simply a newline ("\n"). Vlad set it with [tt]-v ORS=','[/tt]; I thought it would be more clear to set it within the program. [tt]BEGIN[/tt] marks a part of the program that is executed before any lines are read from the input file. [tt]{print}[/tt] is executed for each line read; since we didn't say what to print, awk uses [tt]$0[/tt] (the line just read). Vlad's entire program was
Code:
1
An awk program consists of pairs of this form:
test [tt]{[/tt] actions [tt]}[/tt]
The actions are performed if the test succeeds.
The [tt]{print}[/tt] in my program is a pair like that, but since I omitted the test, it is executed for every line read. Vlad supplied the test ([tt]1[/tt], which is always true) but omitted the action, so awk used the default action [tt]{ print $0 }[/tt].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top