problem with file content extraction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with file content extraction
# 1  
Old 01-19-2012
problem with file content extraction

I need to extract some content of a file.
Example

file abc
vi abc
ooooooooo
bbbbbbbbb
vvv 1234 5
vvv 6789 3
xxxxxxxxxx
xxxxxxxxxx

i want to extract only the following content from file abc and store in another file say temp.
1234 5
6789 3

what should be my approach?
# 2  
Old 01-19-2012
You could print only fields 2 and 3 when a line contains 3 fields..
Code:
awk 'NF==3{print $2,$3}' infile

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-19-2012
If the file structure is the same this would work:

Code:
perl -lne 'print $1 if($_ =~ /.*(\d{4}\s\d{1})/)' file1.txt | tee file2.txt
1234 5
6789 3

cat file2.txt
1234 5
6789 3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem while displaying(cat) file content inside telnet loop .

Hi Team, Not getting the file output inside my email which i am sending from unix box. . Please refer the below code : #!/bin/sh { sleep 5 echo ehlo 10.56.185.13 sleep 3 echo mail from: oraairtel@CNDBMUREAPZP02.localdomain sleep 3 echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Discussion started by: tripathi1990
1 Replies

2. Shell Programming and Scripting

Pattern Search and Extraction Problem

I have something like this: bash-3.2$ svn info Path: . URL: svn+ssh://nlaedev01@10.209.194.15/files0/nlae_dev_svn/repos/newlook-endeca/trunk Repository Root: svn+ssh://nlaedev01@10.209.194.15/files0/nlae_dev_svn/repos/newlook-endeca Repository UUID: 4e8fbe85-c2e2-42fe-a5fa-f9f9100d2393... (3 Replies)
Discussion started by: ankur328
3 Replies

3. Shell Programming and Scripting

Execution Problem with dispalying file content using menu driven script

HI All.. below is my menu options script. in option 2,3 and 4 im giving input and they are saving into their respective text file. problem is when im trying to "cat" those files in options 7,8 and 9 im not getting the output. no respective file contents are displaying on screen. but if i... (1 Reply)
Discussion started by: saichand1985
1 Replies

4. Shell Programming and Scripting

Data Extraction problem in perl

Hello, I want to extract the words from a file which starts with SRD-R or SRD-DR. I have written a script which is able to trace the word but it is printing the whole line. sub extract_SRD_tag{ my ($tag, $app, $path, @data, $word ); $path = shift; $app = shift; open (FILE, $path) or... (2 Replies)
Discussion started by: suvendu4urs
2 Replies

5. Shell Programming and Scripting

Problem getting the content of a file in a shell script variable

Hi, I have a text file that has a long multi-line db2 CTE query. Now I want to store all the contents of this file (i.e. the entire query) in a shell script variable. I am trying to achieve it by this: query = `cat /Folder/SomeFile.txt` But when I echo the contents of this file by saying echo... (4 Replies)
Discussion started by: DushyantG
4 Replies

6. Shell Programming and Scripting

Help with rename header content based on reference file problem

I got long list of reference file >data_tmp_number_22 >data_tmp_number_12 >data_tmp_number_20 . . Input file: >sample_data_1 Math, 5, USA, tmp SDFEWRWERWERWRWER FSFDSFSDFSDGSDGSD >sample_data_2 Math, 15, UK, tmp FDSFSDFF >sample_data_3 Math, 50, USA, tmp ARQERREQR . . Desired... (7 Replies)
Discussion started by: perl_beginner
7 Replies

7. Shell Programming and Scripting

Scan and change file data content problem

Input file >Read_1 XXXXXXXXXXSDFXXXXXDS (condition 1: After the last "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X") TREXXXXXXXSDFXXXXXDS (condition 2: Before the first "X" per line, if the distance is less than or equal to 3 letter,... (12 Replies)
Discussion started by: patrick87
12 Replies

8. Shell Programming and Scripting

Problem in reading a file content

Hi, I am reading a file line by line using read line function of while loop. Each line contains 4 fields. I want to take these 4 values in 4 variables in each iteration so that i can use them in my script. The issue here is that my awk command is returning awkward results - Here is a sample line... (8 Replies)
Discussion started by: garman
8 Replies

9. Shell Programming and Scripting

Problem in piping the file(s) content from zip files

Hi friends I have a zip file 1.zip which contains three text files a.txt b.txt c.txt I want to grep some text(keyword) in those 3 files without extracting all the three files to a local directoryusing the command, unzip -p 1.zip |grep "search text" >result.txt The Output file is... (2 Replies)
Discussion started by: ks_reddy
2 Replies

10. Shell Programming and Scripting

nasty string extraction problem

Hello, if I have a file containing a chunk of HTML and I want to extract always the string beginning http://www.xxx.com/v/ that ends just before "> (i.e. and including the bit BqqtJpfZElQ&hl will change randomly) Any ideas??? # cat randomfeature.html <object width="160"... (3 Replies)
Discussion started by: kevinyeandel1
3 Replies
Login or Register to Ask a Question