Cutting rows at specific length


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cutting rows at specific length
# 1  
Old 01-12-2012
Cutting rows at specific length

Hi, i have a file containing nrows and 3cols. i want to cut it in specific length and save output to individual files.

Code:
1 2 3
4 5 6
5 8 9
10 11 12
13 14 15
16 17 18

i need to cut the file say every 2 rows and save it in individual file.
Code:
01.dat contains
1 2 3
4 5 6
02.dat
7 8 9
10 11 12
03.dat
13 14 15
16 17 18

thanks much.
# 2  
Old 01-12-2012
Code:
awk 'NR%2{b++;fn=b".dat";a=$0;getline;printf("%s\n%s\n",a,$0)> fn}' input.txt

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 01-12-2012
Code:
split -dl2 input outputNamePrefix

This User Gave Thanks to mirni For This Post:
# 4  
Old 01-12-2012
hi, i have a question on this code. what part of this code says that it will cut the values at specific length? thanks much
Code:
awk 'NR%2{b++;fn=b".dat";a=$0;getline;printf("%s\n%s\n",a,$0)> fn}' input.txt

I have 9 files containing each containing 25200 lines. I need to cut each file to 2100 lines that will generate 12 individual output files for each of the original file hence giving me a total of 120 individual files.
Code:
input files: 1999.txt, 2000.txt, 2001.txt, 2002.txt, 2003.txt, 2004.txt, 2005.txt, 2006.txt, 2007.txt

Code:
desired output: 199901.dat ...199912.dat; 200001.dat...200012.dat and so on for the remaining years

many thanks

Last edited by ida1215; 01-12-2012 at 07:28 AM..
# 5  
Old 01-12-2012
Smilie NR%2
# 6  
Old 01-12-2012
thanks balajesuri. now i have updated my previous post and i cant get past incorporating this code to my desired output. any idea? thanks muchSmilie
# 7  
Old 01-12-2012
you can try with split command

read about the -l option
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