How to change rows in file - not only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to change rows in file - not only
# 1  
Old 01-25-2009
How to change rows in file - not only

I have file finish.txt, this file contains (result, path):
Quote:
5:#include "toolbar.h"
...
27:#include "userbox.h"
28:#include "userboxer.h"
/home/user/katalog/podkatalog/podkatalog1/about.cpp
23:#include "misc.h"
...
27:#include "userbox.h"
/home/user/katalog/podkatalog/podkatalog2/about.cpp
10:#include "history.h"
...
29:#include "userbox.h"
/home/user/katalog/podkatalog/podkatalog2/podkatalog3/about.cpp
I would like so that (path, result) in finish.txt:
Quote:
/home/user/katalog/podkatalog/podkatalog1/about.cpp
5:#include "toolbar.h"
...
27:#include "userbox.h"
28:#include "userboxer.h"
/home/user/katalog/podkatalog/podkatalog2/about.cpp
23:#include "misc.h"
...
27:#include "userbox.h"
/home/user/katalog/podkatalog/podkatalog2/podkatalog3/about.cpp
10:#include "history.h"
...
29:#include "userbox.h"
I use only bash (awk, sed, ...)
Thx
# 2  
Old 01-25-2009
nawk -f pat.awk finish.txt

pat.awk:
Code:
BEGIN {
  FS=OFS=":"
}
NF>1 {a= (a) ? a ORS $0 : $0}
NF==1 { print; print a; a=""}
END {
   if (a) {print; print a}
}

# 3  
Old 01-26-2009
Thx
My Unix does not serve nawk Smilie
How to make only awk, sed, ... ?
# 4  
Old 01-26-2009
Quote:
Originally Posted by patrykxes
Thx
My Unix does not serve nawk Smilie
How to make only awk, sed, ... ?
try 'serving' awk...
# 5  
Old 01-26-2009
I'm very sorry. I'm beginner.
Thank you very much Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving or copying first rows and last rows into another file

Hi I would like to move the first 1000 rows of my file into an output file and then move the last 1000 rows into another output file. Any help would be great Thanks (6 Replies)
Discussion started by: kylle345
6 Replies

2. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

3. Shell Programming and Scripting

Extract rows from file based on row numbers stored in another file

Hi All, I have a file which is like this: rows.dat 1 2 3 4 5 6 3 4 5 6 7 8 7 8 9 0 4 3 2 3 4 5 6 7 1 2 3 4 5 6 I have another file with numbers like these (numbers.txt): 1 3 4 5 I want to read numbers.txt file line by line. The extract the row from rows.dat based on the... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

4. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

5. Shell Programming and Scripting

Unix Script file to Append Characters before rows in file.

Hi Experts, I am working on HP-UX. I am new to shell scripting. I would like to have a shell script which will prefix: 1. "H|" before first row of my file and, 2. "T" for all other rows of the file. For Example - File before running the script 20100430|4123451810|218.50|TC 20100430 ... (4 Replies)
Discussion started by: phani333
4 Replies

6. Shell Programming and Scripting

delete rows in a file based on the rows of another file

I need to delete rows based on the number of lines in a different file, I have a piece of code with me working but when I merge with my C application, it doesnt work. sed '1,'\"`wc -l < /tmp/fileyyyy`\"'d' /tmp/fileA > /tmp/filexxxx Can anyone give me an alternate solution for the above (2 Replies)
Discussion started by: Muthuraj K
2 Replies

7. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies

8. Shell Programming and Scripting

change line and rows

hej i have a simple question: is it possible to change rows and lines in a simple textfile with awk or something else? I have: 1 2 3 4 5 6 9 8 7 6 5 4 an I will have: 19 28 37 46 55 64 (1 Reply)
Discussion started by: talia
1 Replies

9. Shell Programming and Scripting

a bit tricky to change it multiple rows in one row and ...

Hi, I have an output file like: 1415971694 376 (12); 3434327831 376 (7); 2989082873 332 (3); 4075357577 332 (3); 1221064374 376 (2); 2372410470 376 (2); 2563564778 332 (2); 443221432 376 (1); ... (2 Replies)
Discussion started by: netbanker
2 Replies
Login or Register to Ask a Question