Format data in new lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format data in new lines
# 1  
Old 01-23-2009
Lightbulb Format data in new lines

Hi All,

I have data in the following format.

Code:
Australia,"CISCO877-SEC-K9
CISCO1841-ADSL
CISCO2821"
Australia,"CISCO877-SEC-K9
CISCO1841-ADSL
CISCO2821"
Austria,"CISCO871-K9
CISCO1841
CISCO1841-SEC/K9
CISCO1812/K9"
Austria,"CISCO1841-SEC/K9
CISCO1812/K9"

The output I want is in the following format

Code:
Australia,CISCO877-SEC-K9
Australia,CISCO1841-ADSL
Australia,CISCO2821
Australia,CISCO877-SEC-K9
Australia,CISCO1841-ADSL
Australia,CISCO2821
Austria,CISCO871-K9
Austria,CISCO1841
Austria,CISCO1841-SEC/K9
Austria,CISCO1812/K9
Austria,CISCO1841-SEC/K9
Austria,CISCO1812/K9

Please let me know the best way to achieve this in a shell/perl script.

Thanks.
# 2  
Old 01-23-2009
Code:
awk -F, '!/^CISCO/ {c=$1; sub(/"/,""); print; next} {sub(/"/,""); print c","$0} ' infile2
Australia,CISCO877-SEC-K9
Australia,CISCO1841-ADSL
Australia,CISCO2821
Australia,CISCO877-SEC-K9
Australia,CISCO1841-ADSL
Australia,CISCO2821
Austria,CISCO871-K9
Austria,CISCO1841
Austria,CISCO1841-SEC/K9
Austria,CISCO1812/K9
Austria,CISCO1841-SEC/K9
Austria,CISCO1812/K9


Last edited by zaxxon; 01-23-2009 at 11:23 AM.. Reason: changed ^C to ^CISCO
# 3  
Old 01-26-2009
$ awk -F, '!/^CISCO/ {c=$1; sub(/"/,""); print; next} {sub(/"/,""); print c","$0} ' infile2
awk: syntax error near line 1
awk: illegal statement near line 1

Excuse my awk knowledge here, but I am not sure what the issue is. Can anyone explain?

Shell is bash shell. Server details where I am running the scripts as follows.
$ uname -a
SunOS 5.8 Generic_108528-29 sun4u sparc SUNW,Ultra-250

Thanks.
# 4  
Old 01-26-2009
On Solaris try nawk instead of awk. Must be there somewhere - I don't know the path to it though, but there are several posts in this forum that point to nawk on Solaris.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format DATA

Input File AU01NAS002,FCNVX133800117,AU01_Melbourne_Australia,ATT,Internal,NAS SILVER,12287.99,3293.98,6946.02 AU01NAS002,FCNVX133800117,AU01_Melbourne_Australia,ATT,Internal,NAS ARCHIVE,12287.99,3327.12,6912.87... (6 Replies)
Discussion started by: greycells
6 Replies

2. UNIX for Dummies Questions & Answers

Data format

Dear Masters, I have problem with my data result I do vim data result AAA111|^/CANADA|80 BAA111|^/PARIS|60 string with blue colour appears..how can I remove it? So when I do vi, blue string should not appear tks (2 Replies)
Discussion started by: radius
2 Replies

3. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

4. Shell Programming and Scripting

Help in replacing two blank lines with two lines of diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script... I used sed to search a line and insert two blank lines after the searchd line using the following sed command. sed "/data/{G;G;}/" filename . In the file, after data tag, two lines got inserted blank lines..... (4 Replies)
Discussion started by: arjun_arippa
4 Replies

5. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

6. Shell Programming and Scripting

How to get data in a specified format

Hii , I have a huge set of data stored in file a.dat as shown below a.dat: 081276A BURMA Date: 1976/ 8/12 Centroid Time: 23:26:51.8 GMT Lat= 26.55 Lon= 97.12 Depth= 15.0 Half duration= 2.2 Centroid time minus hypocenter time: 5.6 Moment Tensor: Expo=24 7.840 -2.440... (4 Replies)
Discussion started by: reva
4 Replies

7. Shell Programming and Scripting

getting the data in some format

HI i am writing a shell script to generate some files having data in some format. for this i am using awk -F":" '{printf("%-20s:%-20s:%-20s:%-20s:%-15s:%-3s:%-19s:%-2s:%-20s:%-15s:%-2s\n", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)}' $DIALPBIN/temp1.txt > ${DIALPBIN}/temp2.txt this helps in... (1 Reply)
Discussion started by: priyanka3006
1 Replies

8. UNIX for Dummies Questions & Answers

Help me to format this data please

Good day, I have a script on each machine on our network that will say the computer name and the number of updates needed. Then the script will send a file via scp to a network share with the title hostname.local The contents of the file would be: hostname N (with N being the number of... (11 Replies)
Discussion started by: glev2005
11 Replies

9. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies

10. Shell Programming and Scripting

format data

i have this data: GREEN LIST : 12321 34534 GREEN LIST : 45645 --- 23423 WHITE LIST : 23479 34534 75483 76924 12345 --- 12351 56778 --- 23330 GREEN LIST : 23567 the output must be: GREEN LIST : 12321 GREEN LIST : 34534 GREEN LIST : 45645 --- 23423 (2 Replies)
Discussion started by: inquirer
2 Replies
Login or Register to Ask a Question