Visit Our UNIX and Linux User Community


How to export some lines from a file to a new file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to export some lines from a file to a new file?
# 1  
Old 10-30-2012
How to export some lines from a file to a new file?

Dear everyone,
I have a big file with many information in it, but I just want some lines.
I don't know exactly what the number of the line I want, I only know some part of these line. It all starts with the word 'F(tot :1 )'
I use grep command and find it. It looks like that on the screen:
F(tot :1) 3 4 5
F(tot :1) 68 7 8
and so on.
I want to insert all lines which I found from the grep command to a new file.
Could you guys please help me how to do it?
I tried google but it doesn't help.
Thanks a lot
# 2  
Old 10-30-2012
Code:
grep 'your-pattern' input_file > new_file

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 10-30-2012
Quote:
Originally Posted by elixir_sinari
Code:
grep 'your-pattern' input_file > new_file

Thanks so much but I still can not get it.
I write the command like that:
grep 'F(tot: 1' ft.09 F1.txt
'ft.09' is the old file, F1.txt is the new one.
Is the command right?

Sorry if the question is so stupid.

---------- Post updated at 02:10 AM ---------- Previous update was at 02:07 AM ----------

I did it!
Thanks a lot.

Before I made a mistake.
I created the file F1.txt before the grep command.
Sorry for bothering
# 4  
Old 10-30-2012
Quote:
Originally Posted by phamnu
grep 'F(tot: 1' ft.09 F1.txt
I created the file F1.txt before the grep command.
Using Elixir's code you don't need to create file before grep.

Code:
grep 'F(tot:  1' ft.09 > F1.txt

If you want to append data into the file then just use >> instead of >.Smilie
This User Gave Thanks to pamu For This Post:
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #915
Difficulty: Easy
In Javascript, 'UNIX.com'.slice(); returns UNIX.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If the 1th column of file f1 and file f2 is the same, then export those line with maximum string of

please help to write a awk command-line programs to achieve the following functions: Thank in advance. Requeset Description: compare two files f1 and f2, export to file f3: 1 Delete duplicate rows of in file f1 and file f2 2 If the 1th column of file f1 and file f2 is the same, then export... (1 Reply)
Discussion started by: weichanghe2000
1 Replies

2. Shell Programming and Scripting

Find all lines in file such that each word on that line appears in at least n lines of the file

I have a file where every line includes four expressions with a caret in the middle (plus some other "words" or fields, always separated by spaces). I would like to extract from this file, all those lines such that each of the four expressions containing a caret appears in at least four different... (9 Replies)
Discussion started by: uncleMonty
9 Replies

3. Shell Programming and Scripting

How to export the string to a text file.

Hi, I have used this find . -type f -exec grep "491629461544" {} \; > test.txt to find the string and export it to file. The problem is, when i used the above command in Shell script, the file is created but the searched string is recursively written in that file and even the file... (10 Replies)
Discussion started by: nanthagopal
10 Replies

4. AIX

wtmp file - is there a patch to export the data another file each day?

sorry for being a noob, i am trying to find which user accessed the server at what time and there ip address at first i used who command but the output didn't contain the ip address then i used the last command which provided me with the ip of the users but when i searched i searched and found that... (1 Reply)
Discussion started by: hercules_1010
1 Replies

5. Shell Programming and Scripting

Extract some lines from one file and add those lines to current file

hi, i have two files. file1.sh echo "unix" echo "linux" file2.sh echo "unix linux forums" now the output i need is $./file2.sh unix linux forums (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

6. Shell Programming and Scripting

help t export the variable from a particular file

Hello Guys, I need you help to do one task I have script which is actually doing to fetch the code of any repository in svn for e.g.:- I can use svn to checkout the repository but I want to checkout the repository for particular tag like svn co <url>/svn/repo/<tag-name> and this... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

7. Shell Programming and Scripting

bash mysql export to file

I'm trying to export a mysql query to a .csv file, right now I'm running a successful query like: us_id=`mysql -u $USER_NAME --password=$PASSWORD -D "databasename" \ -e "SELECT * \ FROM databasename.table \ WHERE somefield >0 AND otherfield ='$ctry' \ ORDER BY... (1 Reply)
Discussion started by: unclecameron
1 Replies

8. Shell Programming and Scripting

How to export a unix file to txt file?

Is there any way by which u can export a file in unix box to a notepad or txt file?:confused: (3 Replies)
Discussion started by: nohup
3 Replies

9. Shell Programming and Scripting

Extra/parse lines from a file between unque lines through the file

I need help to parse a file where there are many records, all of which are consistently separated by lines containing ^============= and "^ End of Report". Example: ============= 1 2 3 4 End of record ============= 1 3 4 End of record Etc.... I only need specific lines... (5 Replies)
Discussion started by: jouuu
5 Replies

10. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

Featured Tech Videos