Adding a line to 1000's of files right after x amt of characters.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding a line to 1000's of files right after x amt of characters.
# 8  
Old 09-22-2012
I'm elated!!! It worked!!!

Boy... that simple find command did EXACTLY what I needed!!!!

Many many thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie

---------- Post updated at 03:13 PM ---------- Previous update was at 03:09 PM ----------

Quote:
Originally Posted by elixir_sinari
Check Post #5 again (I've added some things).

Could you explain what is happening so that I won't ask the same stupid question next time, and so I'll be able to explain it to other people... ?
# 9  
Old 09-22-2012
This Perl one-liner will read a line at a time from the files provided to it (by the shell by expanding Event*; I hope there are only regular files matching that pattern). The name of the current input file will be in the variable $ARGV. To identify the first line of a file, the variable $prev is used. When this variable is not the same as $ARGV, it means the first line of the new file. In this line, the required substitution is made. That is, the first block of data between { and } is matched (through the non-greedy quantifier *?; for more info, use Google) and captured. This is then used (as \1), followed by the required string, in the replacement string.
This User Gave Thanks to elixir_sinari For This Post:
# 10  
Old 09-22-2012
THANKS!!!

Quote:
Originally Posted by elixir_sinari
This Perl one-liner will read a line at a time from the files provided to it (by the shell by expanding Event*; I hope there are only regular files matching that pattern). The name of the current input file will be in the variable $ARGV. To identify the first line of a file, the variable $prev is used. When this variable is not the same as $ARGV, it means the first line of the new file. In this line, the required substitution is made. That is, the first block of data between { and } is matched (through the non-greedy quantifier *?; for more info, use Google) and captured. This is then used (as \1), followed by the required string, in the replacement string.

THANK YOU SO MUCH FOR HELPING ME OUT!!! Smilie
# 11  
Old 09-24-2012
Quote:
Originally Posted by elixir_sinari
This Perl one-liner will read a line at a time from the files provided to it (by the shell by expanding Event*; I hope there are only regular files matching that pattern). The name of the current input file will be in the variable $ARGV. To identify the first line of a file, the variable $prev is used. When this variable is not the same as $ARGV, it means the first line of the new file. In this line, the required substitution is made. That is, the first block of data between { and } is matched (through the non-greedy quantifier *?; for more info, use Google) and captured. This is then used (as \1), followed by the required string, in the replacement string.
Is there a way to check to see if a file ALREADY has the additional line in it so that it doesn't add another line?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a sequence of numbers in a line for 1000 files

Hi, I try to explain my problem , I have a file like this: aasdsaffsc23 scdsfsddvf46567 mionome0001.pdb asdsdvcxvds dsfdvcvc2324w What I need to do is to create 1000 files in which myname line listing a sequence of numbers from 0001 to 1000. So I want to have : nomefile0001.txt that must... (10 Replies)
Discussion started by: danyz84
10 Replies

2. UNIX for Advanced & Expert Users

Help in adding a string at the end of each line and append files vertically

hi, i need a help in the script , need to append a string at the end of each line of a files , and append the files into a single file vertically. eg file1 has the following columns abc,def,aaa aaa,aa,aaa files 2 has the following rows and columns abc,def,aaa aaa,aa,aaa i... (3 Replies)
Discussion started by: senkerth
3 Replies

3. Shell Programming and Scripting

Adding filename and line number from multiple files to final file

Hi all, I have 20 files (file001.txt upto file020.txt) and I want to read them from 3rd line upto end of file (line 1002). But in the final file they should appear to start from line 1. I need following kind of output in a single file: Filename Line number 2ndcolumn 4thcolumn I... (14 Replies)
Discussion started by: bioinfo
14 Replies

4. Shell Programming and Scripting

Adding info to end of line if two columns match from files with different separators

I have two files (csv and vcf) which look exactly like this S1.csv func,gene,start,info "exonic","AL","2309","het" "exonic","NEF","6912","hom"S1.vcf ##fileinfo #CHROM POS ID INFO chr1 4567 rs323211 1/1:84,104,99 chr4 2309 rs346742 1/1:27,213,90 chr6 5834 ... (5 Replies)
Discussion started by: Sarah_19
5 Replies

5. Shell Programming and Scripting

Need help in column comparison & adding extra line to files

Hi, I wanted to check whether the x,y,z coordinates of two files are equal or not. At times, when one file is converted to another suitable file extension , there are some chances that the data mismatch would happen during the conversion. In order to avoid the data misfit, i would like to... (6 Replies)
Discussion started by: b@l@ji
6 Replies

6. Shell Programming and Scripting

adding characters end of line where line begins with..

Hi all, using VI, can anyone tell me how to add some characters onto the end of a line where the line begins with certain charactars eg a,b,c,......., r,s,t,........, a,b,c,......., all lines in the above example starting with a,b,c, I want to add an x at the end of the line so the... (6 Replies)
Discussion started by: satnamx
6 Replies

7. Shell Programming and Scripting

retain last 1000 line in a file

I have large file with around 100k+ lines. I wanted to retain only the last 100 lines in that file. One way i thought was using tail -1000 filename > filename1 mv filename1 filename But there should be a better solution.. Is there a way I can use sed or any such command to change the... (9 Replies)
Discussion started by: nss280
9 Replies

8. Shell Programming and Scripting

Adding characters at the top of all files in directory

Hi Unix experts; I have 30000 files in a directory and am willing to do the following changes on each of them. The input files look like the following: 1 , 2 3 , 4 5 , 6 7 , 8 9 , 10 the output will have # in top 10 lines, insert space instead of comma. This looks like: ... (4 Replies)
Discussion started by: nxp
4 Replies

9. UNIX for Dummies Questions & Answers

Displays line number 1000 to 2000

Hi, I have 1 million records and want to extract lines betwen 10000 -20000 and put it in another file. Could you please suggest a command for this. Thanks in advance (3 Replies)
Discussion started by: unxusr123
3 Replies

10. Shell Programming and Scripting

Command to add 1000 spaces to end of line

hi, could anyone tell me the command to append spaces at the end of the line. for example, i need 1000 spaces after the word "helloworld" echo "helloworld " i need to achieve this in someother way hardcoding 1000 spaces is not practical. as i am totally new... (3 Replies)
Discussion started by: kavithacs
3 Replies
Login or Register to Ask a Question