Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.
need help-unix script
Name: Jernand Date: October 11, 2004 at 09:34:02 Pacific OS: hp-ux CPU/Ram: 1280mb
Comment:
Hi,
I have a file in the format of a listing of item numbers in one column in the (*.xls) -excel file. I would like to have an output in a different format. example: my input will be in the form HEDM-5600#J06 HEDM-5605#B06 HEDM-5605#J06 HEDM-6120#T06 HEDM-6120#T12 and I want an output in the form 'HEDM-5600#J06','HEDM-5605#B06','HEDM-5605#J06','HEDM-6120#T06','HEDM-6120#T12'
where it is prefix with an ' and end with an ' and items are seperated with commas(,). I would like a unix script to handle this job. Please help.
Name: Jim Boothe Date: October 11, 2004 at 11:24:02 Pacific
Reply:
Everything on a single line?
awk ' {printf "%s\047%s\047",comma,$1 comma=","} END {printf "\n"} ' myfile
0
Response Number 2
Name: Jernand Date: October 11, 2004 at 14:18:03 Pacific
Reply:
Thanks a lot Jim, that works...
Regards, Jern
0
Response Number 3
Name: Jernand Date: October 11, 2004 at 14:20:23 Pacific
Reply:
Hi Jim,
Can you please explain me the awk listings? eg, 047. thanks.
Regards, Jern
0
Response Number 4
Name: Jim Boothe Date: October 12, 2004 at 06:50:44 Pacific
Reply:
The \047 is not particular to awk, but instead basic unix (do man echo). You can represent any ascii character (printable or not) using a backslash followed by the numerical octal value.
That was just one way for me to get the single-quotes hardcoded into my output.
0
Response Number 5
Name: Jim Boothe Date: October 12, 2004 at 07:26:50 Pacific
Reply:
Regarding printf (formatted print), this is also common to unix. You can execute printf commands from the unix prompt (man printf).
In the awk printf below, the format mask (in double-quotes), specifies: col for 6-char string (min) constant string ": " col for number (show 2 dec) constant string " GB" newline (end-of-line term) Following the format mask, I must feed it two values to populate the two columns (represented by the % formats). In this case, the first value is the second word of the line, and the second value is a mathematical expression.
Summary: HI there, if anyone can help me it will be much appreciated. I need to make a bourne shell script which will ping a total of 30 servers to make sure they are alive and then print the records onto a f...
Summary: Hi all, I have a lot of similar files that i have to update. I need an unix script that scan all these file, looking for old templet and replace it with new one. for example: I have two similar files,...
Summary: Hi Everyone, I need help with Unix. I have to write a script that will convert currency. It has to convert US to Canadian dollars and vice versa. And it should be able to convert anyother currency....