Cutting rows at specific length


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cutting rows at specific length
# 8  
Old 01-12-2012
Actually, the NR%2 part in the awk command is not needed. This will work just as well:
Code:
awk '{fn=++b".dat";a=$0;getline;printf("%s\n%s\n",a,$0)> fn}' file

What makes it grab two lines is the 'getline' command.
Awk takes one line at a time, so it holds one line as $0, which is saved into 'a' var, then getline will load another line into $0, then the two lines are printed.

Using split:
Code:
for i in {1999..2008} ; do 
    split -d -l 2100 $i.txt $i 
    for j in {11..0} ; do 
        mv ${i}${j} ${i}$((j+1)).txt
    done
done

The inner for loop will rename the files output by split, which are 199900, 199901, ... 199911 to 199901.txt, ... 199912.txt.
This User Gave Thanks to mirni For This Post:
# 9  
Old 01-12-2012
@ mirni: Thanks so much for clearing things out and for the code as well.Smilie

---------- Post updated at 01:00 AM ---------- Previous update was at 12:35 AM ----------

hi mirni, im getting this error when running the code.
Code:
mv: cannot stat `20074': No such file or directory
mv: cannot stat `20073': No such file or directory
mv: cannot stat `20072': No such file or directory
mv: cannot stat `20071': No such file or directory
mv: cannot stat `20070': No such file or directory

# 10  
Old 01-12-2012
Oops, sorry. I forgot to take care of leading zeros. Here:
Code:
for i in {1999..2008} ; do
   split -d -l 2100 $i.txt $i 
   for j in {11..0} ; do 
       j0=`printf "%02d" $j`
       j1=`printf "%02d" $((j+1))` 
       mv ${i}${j0} ${i}${j1}.txt 
   done
done

This User Gave Thanks to mirni For This Post:
# 11  
Old 01-12-2012
Thanks a bunch ,Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cutting specific columns from lines

I am trying to remove columns 81-97 from a line that can be as long as 114 characters. Because a number of lines might not have under 80 characters, using the cut command following by paste could be a problem. While sed might work, is there some other utility that could do this more easily? ... (9 Replies)
Discussion started by: wbport
9 Replies

2. Shell Programming and Scripting

Append spaces the rows to make it into a required fixed length file

I want to make a script to read row by row and find its length. If the length is less than my required length then i hav to append spaces to that paritucular row. Each row contains special characters, spaces, etc. For example my file contains , 12345 abcdef 234 abcde 89012 abcdefgh ... (10 Replies)
Discussion started by: Amrutha24
10 Replies

3. Shell Programming and Scripting

combining cat output and cutting rows

I have a file that contain the following. -D HTTPD_ROOT="/usr/local/apache" -D SERVER_CONFIG_FILE="conf/httpd.conf" I want a shell script, so that after cat filename and apply the shell script I should get the output as follows. /usr/local/apache/conf/httpd.conf ie cat filename |... (7 Replies)
Discussion started by: anilcliff
7 Replies

4. Shell Programming and Scripting

Cutting out text from specific portion on filename

Hi, how do I go about cutting out the first numeric characters after the word "access"? access1005101228.merged-00.15.17.86.d8.b8.log.gz (16 Replies)
Discussion started by: GermanJulian
16 Replies

5. Shell Programming and Scripting

Cutting specific line of a file by checking condition

testfile.csv 0","1125209",,"689202CBx18888",,"49",,,"NONMC",,,,,"01112010",,,,,,,"MTM- "1","",,"689202ABx19005",,"49",,,"NONMC",,,,,"01072010",,,,,,,"MTM- testfile.csv looks like above format if the second column is null then get 23rd column and store in a different varible .. add all the... (1 Reply)
Discussion started by: mgant
1 Replies

6. 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

7. Shell Programming and Scripting

Cutting specific lines from a file

Hi, I have a file named Mani.txt. The contents are like this cat Mani.txt -------------------------------------------------------- Hi there how r u My Name is Mani Bye ------------------------------------------------------------ I want to cut the first and last lines from the file... (15 Replies)
Discussion started by: pathanjalireddy
15 Replies

8. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

9. Shell Programming and Scripting

Cutting specific name from configuration file

Hi falks, I have the following configuration file structure: file1:N file2:Y file3:Y file4:N ...... I need to cut from the configuration file only the file with the sign "Y" in the end and copy it to some directory. What is the best way to do it? Thanks in advance, Nir (8 Replies)
Discussion started by: nir_s
8 Replies

10. Shell Programming and Scripting

Cutting rows after a selected point

I have a log file from which I want to cut out the ten lines assoictiated to my search requirment (cust_ref #). The cust_ref number will be on te first line and the update information will be on the following ten lines (which dosen't linking data to grep on). Using a script I would like to... (4 Replies)
Discussion started by: nhatch
4 Replies
Login or Register to Ask a Question