Extract few content from a huge list of files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract few content from a huge list of files
# 1  
Old 01-09-2014
Extract few content from a huge list of files

I have a huge list of files (about 300,000) which have a pattern like this.

Code:
.I 1
.U
87049087
.S
Am J Emerg
.M
Allied Health Personnel/*; Electric Countershock/*;
.T
Refibrillation managed by EMT-Ds:
.P
ARTICLE.
.W
Some patients converted from ventricular fibrillation to organized rhythms by defibrillation-trained ambulance technicians (EMT-Ds) will refibrillate before hospital arrival. The authors analyzed 271 cases o.
.A
Stults KR.

I want to extract only two fields from this file, and store in a separate file. So my output should be:
Code:
.U
87049087
.W
Some patients converted from ventricular fibrillation to organized rhythms by defibrillation-trained ambulance technicians (EMT-Ds) will refibrillate before hospital arrival. The authors analyzed 271 cases o.

What I have been trying for sometime now is to first extract the line after
Quote:
.U
, using the following code:
Code:
awk '/\.U/{c=2}c&&c--' file

and then I used this code in another step to extract the pattern after
Quote:
.W
:
Quote:
awk 'f;/pattern/{f=1}' file
. But these two codes are not at all proving to be effective for me. Is there any better way of extracting those contents? I am using Linux with BASH.

Last edited by shoaibjameel123; 01-09-2014 at 03:27 AM..
# 2  
Old 01-09-2014
You were very close, just change:
Code:
awk '/\.U/{c=2}c&&c--' file

to:
Code:
awk '/\.[UW]/{c=2}c&&c--' file

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing two files and list the difference with common first line content of both files

I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ? Source File ************* # file: /local/test_1 # owner: own #... (4 Replies)
Discussion started by: sarathy_a35
4 Replies

2. Shell Programming and Scripting

List the files after sorting based on file content

Hi, I have two pipe separated files as below: head -3 file1.txt "HD"|"Nov 11 2016 4:08AM"|"0000000018" "DT"|"240350264"|"56432" "DT"|"240350264"|"56432" head -3 file2.txt "HD"|"Nov 15 2016 2:18AM"|"0000000019" "DT"|"240350264"|"56432" "DT"|"240350264"|"56432" I want to list the... (6 Replies)
Discussion started by: Prasannag87
6 Replies

3. Shell Programming and Scripting

Extract a list of files using unzip command

Hi all, this is my first and i can't speak english well, so please be kind ! Here is my problem : I want to unzip a list of .zip files stored in one directory, so I though about using that : unzip '*.zip' Thing is that all of my zipped folders contain a file with the unique same name :... (6 Replies)
Discussion started by: remissssss
6 Replies

4. Shell Programming and Scripting

Excution Problems with loading huge data content and convert it

Hi, I got long list of referred file content: CGTGCFTGCGTFREDG PEOGDKGJDGKLJGKL DFGDSFIODUFIODSUF FSDOFJSODIFJSIODFJ DSFSDFDFSDOFJFOSF SDFOSDJFOJFPPIPIOP . . . Input file content: >sample_1 SDFDSKLFKDSLSDFSDFDFGDSFIODUFIODSUFSDDSFDSSDFDSFAS (14 Replies)
Discussion started by: patrick87
14 Replies

5. Shell Programming and Scripting

How to extract a subset from a huge dataset

Hi, All I have a huge file which has 450G. Its tab-delimited format is as below x1 A 50020 1 x1 B 50021 8 x1 C 50022 9 x1 A 50023 10 x2 D 50024 5 x2 C 50025 7 x2 F 50026 8 x2 N 50027 1 : : Now, I want to extract a subset from this file. In this subset, column 1 is x10, column 2 is... (3 Replies)
Discussion started by: cliffyiu
3 Replies

6. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

7. Shell Programming and Scripting

Shell script or command help to extract specific contents from a long list of content

Hi, I got a long list of contents: >sequence_1 ASSSSSSSSSSSDDDDDDDDDDDCCCCCCC ASDSFDFFDFDFFWERERERERFSDFESFSFD >sequence_2 ASDFDFDFFDDFFDFDSFDSFDFSDFSDFDSFASDSADSADASD ASDFFDFDFASFASFASFAFSFFSDASFASFASFAFS >sequence_3 VEDFGSDGSDGSDGSDGSDGSDGSDG dDFSDFSDFSDFSDFSDFSDFSDFSDF... (2 Replies)
Discussion started by: patrick87
2 Replies

8. Shell Programming and Scripting

Extract content from several txt-files

Hi! Im trying to write a script in ksh that creates a single txt-file from specific content in several other txt-files. From these files I want to extract all text after 'WORD' and before '=', regardless of number of lines and other content. I have tried cat and guess I need... (7 Replies)
Discussion started by: larsu
7 Replies

9. Shell Programming and Scripting

How to extract a piece of information from a huge file

Hello All, I need some assistance to extract a piece of information from a huge file. The file is like this one : database information ccccccccccccccccc ccccccccccccccccc ccccccccccccccccc ccccccccccccccccc os information cccccccccccccccccc cccccccccccccccccc... (2 Replies)
Discussion started by: Marcor
2 Replies

10. Shell Programming and Scripting

How to extract data from a huge file?

Hi, I have a huge file of bibliographic records in some standard format.I need a script to do some repeatable task as follows: 1. Needs to create folders as the strings starts with "item_*" from the input file 2. Create a file "contents" in each folders having "license.txt(tab... (5 Replies)
Discussion started by: srsahu75
5 Replies
Login or Register to Ask a Question