Computing.Net > Forums > Unix > need help-unix script

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

Reply to Message Icon

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.

Regards,
Jern



Sponsored Link
Ads by Google

Response Number 1
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.

echo 13463240 /u01 |
awk '{printf "%6s: %6.2f GB\n",$2,$1/1024}'

 /u01: 13147.70 GB


0

Related Posts

See More



Response Number 6
Name: Jernand
Date: October 12, 2004 at 16:12:31 Pacific
Reply:

Thanks a bunch, Jim.

Regards,
Jern


0
Reply to Message Icon

Negate a Regular Expressi... Alert mail



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: need help-unix script

Need a unix script to ping servers www.computing.net/answers/unix/need-a-unix-script-to-ping-servers-/5090.html

unix script - find and replace www.computing.net/answers/unix/unix-script-find-and-replace/5816.html

unix scripting help needed. www.computing.net/answers/unix/unix-scripting-help-needed/2473.html