Add row, awk, sed ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add row, awk, sed ?
# 1  
Old 12-16-2008
Add row, awk, sed ?

I wrote script in bash which generates this report:

phrase1;phrase2;phrase3;phrase4;phrase5;phrase6;phrase7;phrase8
phrase9;phrase2;phrase10;phrase4;phrase11;phrase12;phrase13;phrase14
phrase15;phrase16;phrase17;phrase18;phrase19;phrase20;phrase21;phrase22
...

I would like add name only columns, for example:

Column1;Column2;Column3;Column4;Column5;Column6;Column7;Column8
phrase1;phrase2;phrase3;phrase4;phrase5;phrase6;phrase7;phrase8
phrase9;phrase2;phrase10;phrase4;phrase11;phrase12;phrase13;phrase14
phrase15;phrase16;phrase17;phrase18;phrase19;phrase20;phrase21;phrase22
...

How to do this ?
Thx
# 2  
Old 12-16-2008
To prepend a text with a new first line use:

Code:
sed '1 s/^/sometext\n/' infile > outfile

I hope this helps.

bakunin
# 3  
Old 12-16-2008
Quote:
sed '1 s/^/sometext\n/' infile > outfile
This command show:

Column1
phrase1;phrase2;phrase3;phrase4;phrase5;phrase6;phrase7;phrase8
phrase9;phrase2;phrase10;phrase4;phrase11;phrase12;phrase13;phrase14
phrase15;phrase16;phrase17;phrase18;phrase19;phrase20;phrase21;phrase22
...

I would like this:

Column1;Column2;Column3;Column4;Column5;Column6;Column7;Column8
phrase1;phrase2;phrase3;phrase4;phrase5;phrase6;phrase7;phrase8
phrase9;phrase2;phrase10;phrase4;phrase11;phrase12;phrase13;phrase14
phrase15;phrase16;phrase17;phrase18;phrase19;phrase20;phrase21;phrase22
...

maybe awk ?
Thx
# 4  
Old 12-16-2008
I use:

Quote:
sed '1 s/^/column1;column2;column3;column4;column5;column6;column7;column8\n/' infile > outfile
Thank you very much Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to skip header row and add string to field

The awk below does put in VUS in the 9th field but I can not seem to skip the header then add the VUS. I tried to incorporate NR >=2 and NR > 1 with no luck. Thank you :). input Chr Start End Ref Alt Func.refGene PopFreqMax CLINSIG Classification chr1 43395635 ... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Reading and appending a row from file1 to file2 using awk or sed

Hi, I wanted to add each row of file2.txt to entire length of file1.txt given the sample data below and save it as new file. Any idea how to efficiently do it. Thank you for any help. input file file1.txt file2.txt 140 30 200006 141 32 140 32 200006 142 33 140 35 200006 142... (5 Replies)
Discussion started by: ida1215
5 Replies

3. Shell Programming and Scripting

Awk/sed script for transposing any number of rows with header row

Greetings! I have been trying to find out a way to take a CSV file with a large number of rows, and a very large number of columns (in the thousands) and convert the rows to a single column of data, where the first row is a header representing the attribute name and the subsequent series of... (3 Replies)
Discussion started by: tntelle
3 Replies

4. Shell Programming and Scripting

add and subtract specific row using awk

Hi Folks I have tried awk command to conditionally add or subtract value from specific row in a file. The test file looks like: # cat test.txt cont x y Max 0.3 0.9 Min 0.2 0.9 diff 0.1 0 # awk '{for (i=2; i <=NF; i++) if ($i== "0") $i=$i+0.2; print}' test.txt Output: cont... (1 Reply)
Discussion started by: dixits
1 Replies

5. Shell Programming and Scripting

Awk to add selected row column data

Looks at the most efficient way to add up the column of data based off of the rows. Random data Name-Number-ID Sarah-2.0-15 Bob-6.3-15 Sally-1.0-10 James-1.0-10 Scotty-10.7-15 So I would select all those who have ID = 15 and then add up total number read - p "Enter ID number" Num ... (3 Replies)
Discussion started by: Ironguru
3 Replies

6. Shell Programming and Scripting

Combining multiple rows in single row based on certain condition using awk or sed

Hi, I'm using AIX(ksh shell). > cat temp.txt "a","b",0 "c",bc",0 "a1","b1",0 "cc","cb",1 "cc","b2",1 "bb","bc",2 I want the output as: "a","b","c","bc","a1","b1" "cc","cb","cc","b2" "bb","bc" I want to combine multiple lines into single line where third column is same. Is... (1 Reply)
Discussion started by: samuelray
1 Replies

7. Shell Programming and Scripting

awk/sed to get unique row

Hello ALL, I have very huge file almost 25G size contents of the file are "|" delimited columns on each row eg: 1396745|1078529|KDS|2011-04-21 00:00:00.0|1100|30|2|2011-04-20 22:35:24.0|2011-04-20 22:35:24.0|0|2011-04-21 00:00:00.0|1100|2222434|2011-04-21 11:00:00.0|0|0|2011-06-29... (10 Replies)
Discussion started by: posner
10 Replies

8. Shell Programming and Scripting

Replace last row of a column in bash/awk/sed

Hi, I've got a file with 3 columns which ends like this: ... 1234 345 1400 5287 733 1400 8472 874 1400 9317 726 1400 I want to replace the last row of the last column with the value 0. So my new file will end: ... 1234 345 1400 5287 733 1400 8472 874 1400 9317 726 ... (5 Replies)
Discussion started by: jhunter87
5 Replies

9. Shell Programming and Scripting

shell script(Preferably awk or sed) to print selected number of columns from each row

Hi Experts, The question may look very silly by seeing the title, but please have a look at it clearly. I have a text file where the first 5 columns in each row were supposed to be attributes of a sample(like sample name, number, status etc) and the next 25 columns are parameters on which... (3 Replies)
Discussion started by: ks_reddy
3 Replies

10. Shell Programming and Scripting

help with sed to add delimiter and new field to each row

I have a file with millions of rows that I need to add a delimiter and a new field with a zero to the end of each row. (its too big to open and do a find and replace regex) I'm looking for the next line '\n' and need to replace it with a Unit Separator (hex \037) 0 \n. I've tried the... (2 Replies)
Discussion started by: kmac
2 Replies
Login or Register to Ask a Question