Urgent Need Help! Merging lines in .txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Urgent Need Help! Merging lines in .txt file
# 8  
Old 07-05-2008
I'm a begginer awk user and not sure how to use nawk. Is there a way to make the first code work for awk?
O, and your output was correct. I didn't treat the last line correctly!

Last edited by awknerd; 07-05-2008 at 05:00 PM..
# 9  
Old 07-05-2008
Yes. This is Old-AWK compatible:

Code:
awk '1 == NR || $NF >= 1000 {
  if (c) print _, __ 
  _ = $1 FS $2
  c = 1
  }  
{ __ = $3 }
END { 
  print _, __ 
  } ' file

To run the original code under the New AWK just invoke the correct interpreter:

Code:
nawk 'END { print _, __ } 
1 == NR || $NF >= 1000 {
  if (c) print _, __ 
  _ = $1 FS $2
  c = 1
  }  
{ __ = $3 }' file

# 10  
Old 07-05-2008
It WORKED! Thanks so much!! The way you had it was perfect, for some reason, it just had problems when I cut and paste it, and use dos2unix. But in the end, it worked. Thank you!

Last edited by awknerd; 07-06-2008 at 03:00 AM..
# 11  
Old 07-05-2008
It worked! I was having copy and pasting problems..

Last edited by awknerd; 07-06-2008 at 03:06 AM..
# 12  
Old 07-06-2008
Quote:
Originally Posted by awknerd
The first code for awk is still not working for me. Are there supposed to be commas after the first print command? I am using

Code:
 
awk '1 == NR || $NF >= 1000 { if (c) print _, __, _ = $1, FS, $2; c = 1 } { __ = $3 } END { print _, __ } ' file

If you're going to put it all on one line, try it like this:

Code:
 
awk '1 == NR || $NF >= 1000 { if (c) print _, __; _ = $1 FS $2; c = 1 } { __ = $3 } END { print _, __ } ' file

# 13  
Old 07-06-2008
Thanks. I didn't realize that copying and pasting onto a WordPad document then saving it as .txt, then doing dos2unix file.txt didn't work. So I tried pasting it just to notepad, doing dos2unix on it, and it worked. Lesson learned! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merging the lines of a file

Hello, I have a file with few lines starting with a digit (1-5 only ) followed by a dot (.). Remaining all the lines to be merged with its previous numbered lines. Merging must be done with a space. E.g., Source file: 3. abc def xyz 5. pqr mno def 4. jkl uvw 7. ghi 1. abc xyz 6. mno... (4 Replies)
Discussion started by: magnus29
4 Replies

2. Shell Programming and Scripting

Merging multiple files using lines from one file

I have been working of this script for a very long time and I have searched the internet for direction but I am stuck here. I have about 3000 files with two columns each. The length of each file is 50000. Each of these files is named this way b.4, b.5, b.6, b.7, b.8, b.9, b.10, b.11, b.12... (10 Replies)
Discussion started by: iconig
10 Replies

3. Shell Programming and Scripting

merging two .txt files by alternating x lines from file 1 and y lines from file2

Hi everyone, I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines). Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
Discussion started by: ink_LE
6 Replies

4. Shell Programming and Scripting

sed to cp lines x->y from 1.txt into lines a->b in file2.txt

I have one base file, and multiple target files-- each have uniform line structure so no need to use grep to find things-- can just define sections by line number. My question is quite simple-- can I use sed to copy a defined block of lines (say lines 5-10) from filename1.txt to overwrite an... (3 Replies)
Discussion started by: czar21
3 Replies

5. Shell Programming and Scripting

Merging lines in a text file

hi, I have a file as below: Name: some_name Date: some_date Function Name: <some_function_name(jjjjjjjjj, fjddddd, gggg, ggg)> Changes:<Change A more of change A> Name: some_name Date: some_date Function Name: some_function_nameB(jjjjjjjjj, fjddddd, gggg, ggg) Changes:Change B... (15 Replies)
Discussion started by: flamingo_l
15 Replies

6. Shell Programming and Scripting

Urgent help needed on merging lines with similar words

Hi everyone, I need help with a merging problem. Basically, I have a file with several lines (in this example 9 lines) such as: Amie, Jay, Sasha, Rob, Kay Mia, Frank Jay, Nancy, Cecil Paul, Ked, Nancy, 17, Fred 14, 16, 18, 20 9, 11 12, Frank 18, Peter, 62 Nancy, 27 A delimiter is... (3 Replies)
Discussion started by: awb221
3 Replies

7. Shell Programming and Scripting

Merging lines in a file

Hi, I want to merge the lines starting with a comma symbol with the previous line of the file. Input : cat file.txt name1,name2 ,name3,name4 emp1,emp2,emp3 ,emp4 ,emp5 user1,user2 ,user3 Output name1,name2,name3,name4 emp1,emp2,emp3,emp4,emp5 (9 Replies)
Discussion started by: mohan_tuty
9 Replies

8. Shell Programming and Scripting

Merging lines based on occurances of a particular character in a file

Hi, Is there any way to merge two lines based on specific occurance of a character in a file. I am having a flat file which contains multiple records. Each row in the file should contain specified number of delimiter. For a particular row , if the delimiter count is not matched with... (2 Replies)
Discussion started by: mohan_tuty
2 Replies

9. UNIX for Dummies Questions & Answers

merging two lines in a file

Hi All, I want to merge two lines in a file till the end of the file. So what could be the command to get so. say file name : sample.txt contents: country=1 send apps =1 rece=2 country=2 send apps =3 rece=3 .. ... output: country=1;send apps =1 rece=2 country=2;send apps =3... (6 Replies)
Discussion started by: thaduka
6 Replies

10. Shell Programming and Scripting

[Urgent]how to print the file names into a txt file???

HI, I have a folder with some 120 files...i just want to print all the file filenames(not the content or anything else) onto a file say .txt. please help me with this command Thanks a lot. (15 Replies)
Discussion started by: kumarsaravana_s
15 Replies
Login or Register to Ask a Question