Help with editing 2nd line after match


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with editing 2nd line after match
# 1  
Old 04-06-2011
Lightbulb Help with editing 2nd line after match

Hi All
I would like to break down each next line that matches SK1.chr* in this case NNNNNN.... into 100 characters each after
Code:
SK1.chr*
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

Can someone help me figure this out if there is a Perl way to do. I'm learning Perl so I would appreciate Perl specific solutions.
Cheers Smilie
# 2  
Old 04-06-2011
Code:
man fold

?
Code:
fold -w 100 infile

?
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 04-06-2011
Yeah that did the job ... I didnt know about the fold command .. Cheers Smilie

---------- Post updated at 09:05 AM ---------- Previous update was at 09:00 AM ----------

What if I had to write the edited output as a separate file using the first line as file name? I know I can do this using > operator and output_filename, but I want to automatise this for the whole big file. My original file has several such lines so I would like to have multiple files as output.
Cheers Smilie
# 4  
Old 04-06-2011
Try:
Code:
perl -ln0e 'while(/(SK1.*)\n(.*)/g){$x=$2;open O,">$1";$x=~s/.{100}/$&\n/g;print O $x;}' file

This User Gave Thanks to bartus11 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. Shell Programming and Scripting

Search from 1st match and end 2nd match

I've been looking through the forums for awhile now and looking at the man page for grep and egrep and not seeming to find this scenario so it might not be possible but figured I'd throw it out to get some ideas. I'm looking for a way to search a file for 1st match (example below net self) and... (3 Replies)
Discussion started by: djzah
3 Replies

3. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

4. Shell Programming and Scripting

Editing in vi - adding words to a line

i have lines in a file similar to this: results=$(echo Total: ${res} | command | command) now I need to add text before the word "results", but i dont know how to do it. here's what i tried: %s~results=.*echo Total:.* ${7}~PROCESS \; results=.*echo Total:.* ${7}~g the problem is,... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

6. Shell Programming and Scripting

Editing the next line of the pattern

Hi All, I am trying to edit the next line when there is a success for a pattern. For example: <nvname>abc</nvname> <nvvalue>1</nvvalue> <nvname>def</nvname> <nvvalue>2</nvvalue> once there is a hit for the string "abc" the value of the nvvalue should be replaced with the value we... (5 Replies)
Discussion started by: pulgupta
5 Replies

7. Shell Programming and Scripting

Editing the first line of file

I have a sample file as below :- RECORD_COUNT|2660|28606946.86|20110701122349694| adkad|wwsgesg|mkmk|FFFF|FAFAF|FFAF|FAFFFFA|5894858| I have to replace the second coulmn in the first row which is the count of no of lines in the file from a new variable . Also I have to delete the 3rd... (2 Replies)
Discussion started by: Sanjeev Yadav
2 Replies

8. UNIX for Dummies Questions & Answers

Line editing

I have some trouble editing a line. My aim is to edit the first line of a file.It will look the code and if there are dummy characters at the begininng of line before < it will erase. It is a php code.For instance: for instance if the first line is like %^<?php>sadsa</php>, it will change it to... (6 Replies)
Discussion started by: king87
6 Replies

9. Shell Programming and Scripting

awk line editing

Hello I am trying to make an awk script that always replaces the same characters in a file, with white space in between. Can anyone write a script that prompts for the 3 numbers and then replaces them in the file? eg. enter a b c: 'it then puts a b c in the file. The file format is always ... (12 Replies)
Discussion started by: gav2251
12 Replies

10. Shell Programming and Scripting

Editing last line of a file

Hi All, Could you please help me out with this problem? I need to edit the last line of my file. Ex: The last line in my file will be say 000056000045 8 I need to subtract some number from the number 45 and replace the new number in its place. ... (1 Reply)
Discussion started by: Anitha Chandran
1 Replies
Login or Register to Ask a Question