Creating a new file with each line of a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a new file with each line of a text file
# 1  
Old 05-22-2012
Creating a new file with each line of a text file

Hello,

I would like to make a script in c-shell, using sed comand, but i don know how to do this task:
I have a file name data in /home/user/IMPUT with several text lines:

1144088 2012/05/21 23:20:08 36.8505 -11.2618 0 4.3(mb)

1143593 2012/05/18 13:12:12 34.0526 1.8096 0 4.7(mb)

1143384 2012/05/17 05:07:30 36.8650 -12.3306 0 4.6(mb)

1143167 2012/05/15 10:05:48 36.9128 -12.2563 0 3.6(mb)


The first one is always a blank line and there is a blank line between each line text, as you can see.
How could I write every single line in a different output file?

Thanks in advance.
# 2  
Old 05-22-2012
Code:
 sed '/^$/d' IMPUT| awk '{print > "File_"NR".txt"}'

OR

Code:
awk '!/^$/{print  > "File_"NR".txt" }' IMPUT

# 3  
Old 05-22-2012
split

See if your shell can acept split command.

I tried this in ksh and it worked.

Code:
split -l 2 input.txt output

The l switch is used to direct nr of lines to output. I have given 2 to count the blank line following actual data line as well.
# 4  
Old 05-22-2012
Thanks a lot!!!
I have used split command and it works.

Now I need to do it in another way, without creating new text files from every file's text line:
I would like to make a script in c-shell, using a loop (for command), which for each odd line in my imput text file -> don't do anything, and for each even line -> run several programs.

Any suggestion please??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

2. Shell Programming and Scripting

crontab not creating text file

while running the following code in ssh crontab, Its running successfully but its not creating text file IFC1.txt, file1.txt, file2.txt while running manually its working. please help me #!/bin/ksh hostname > file1.txt 2>/dev/null hostname >> file1.txt 2>/dev/null sudo df -h | grep... (2 Replies)
Discussion started by: elango963
2 Replies

3. Shell Programming and Scripting

Help for reformatting text file and creating new format

Hi all, I have an input file like 1,date,company,, 1,date,comapny,, 2,000,,,567,ACT,00,,,,KKG,M1,D45,,67J,+4500000000 2,000,,,567,ACT,00,,,,KKG,M6,D49,,56J,+6000 2,000,,,567,ACT,00,,7,,KKG,M3,D58,,68h,-70000 2,000,,,567,ACT,00,,,,KKG,M9,D95,,34m,0.00 3,total what i require is 1.I... (2 Replies)
Discussion started by: selvankj
2 Replies

4. Shell Programming and Scripting

Help in creating a text file

Hi, I need help in creating a file in specific format. I have following lines in a file 0772 0ECC 0FC8 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 (6 Replies)
Discussion started by: jpkumar10
6 Replies

5. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

6. UNIX for Dummies Questions & Answers

creating text file with content from script

hi, can somebody tell me how I can create a text file with content from Bash script. The file should be prefilled with information such as current date and time then leaving the user ability to input more data right below those prefilled content. thank you :) (0 Replies)
Discussion started by: s3270226
0 Replies

7. Shell Programming and Scripting

Help with creating a text file in perl with file creation date.

Hi, I am quite new to Perl scripting and i need to create a .TXT file using perl, with fields (A,B,C,D,E), and this text file should be named with current file creation date "XYZ_CCYYMMDD.TXT" (i.e.XYZ_2011042514:33 PM). Can anyone who has done this, please share their expertise on this... (5 Replies)
Discussion started by: msrahman
5 Replies

8. Homework & Coursework Questions

creating search script for a text file

I am aware of the stipulations regarding homework, however I am completely stuck and do not know how to even begin the following (in bash): Create a script that searches for a text file with most occurrences of a given keyword. Any help is greatly appreciated. Thank you (1 Reply)
Discussion started by: hybridoutlaw
1 Replies

9. Shell Programming and Scripting

Creating a text file in Local Drive

Hi All, I am new in Shell Script. I have a ksh script running in the Unix Server and basically in that script I need to create a text file but the text file has to be generated in the local PC (the user computer such as in C:\ drive). I have no idea on how to do it and I need it pretty urgently.... (2 Replies)
Discussion started by: yramli
2 Replies

10. UNIX for Dummies Questions & Answers

Creating flat text file (ASCII)

Hi everybody. I need help and I hope someone is willing to help me out here. My wholesale company is currently moving to new software. The old software is running on a UNIX platform. We need to migrate data from the UNIX system, but our former software provider refuses to assist the data... (5 Replies)
Discussion started by: Wdonero
5 Replies
Login or Register to Ask a Question