Separating delimited file by pattern with exclusion list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Separating delimited file by pattern with exclusion list
# 1  
Old 07-27-2010
Separating delimited file by pattern with exclusion list

I have a file with the contents below

Code:
jan_t=jan;feb_t=feb;mar_t=mar;year=2010
jan_t=null;feb_t=feb;mar_t=mar;year=2010
jan_t=jan;feb_t=feb;mar_t=mar;year=2010

I want to extract out all the fields values ending with "_t" , however, i want to exclude feb_t and mar_t from the results

In addition, I want to print the whole line whenever jan_t=null,

so the end product should look something like this

Code:
jan
jan_t=null;feb_t=feb;mar_t=mar;year=2010
jan



how do I do that? thank you.

Last edited by vgersh99; 07-27-2010 at 04:14 PM.. Reason: code tags, please!
# 2  
Old 07-27-2010
Code:
# sed '/jan_t=[^null]/s/.*/jan/' infile
jan
jan_t=null;feb_t=feb;mar_t=mar;year=2010
jan

# 3  
Old 07-27-2010
Code:
sed -n "/jan_t=null/{p;n;};s/[^_]*_t=\([^;]*\);.*/\1/p" file

# 4  
Old 07-27-2010
Code:
# sed "s/\(jan\)_t=[^null].*/\1/" infile
jan
jan_t=null;feb_t=feb;mar_t=mar;year=2010
jan

# 5  
Old 07-27-2010
Code:
awk '/jan_t=null/ {print;next} 
       /feb_t/||/mar_t/ {split($0,a,"_");print a[1]}' urfile

# 6  
Old 07-28-2010
Hi

Code:
awk -F '[=;]' '$2!="null"{print $2;next}1' file

Guru.
# 7  
Old 07-28-2010
Code:
#!/bin/bash

while read -r LINE
do
   LINE="${LINE/feb_t/}"
   LINE="${LINE/mar_t/}"
   case "$LINE" in
   "jan_t=null"* ) echo "$LINE";;
   *"_t"* )
   IFS=";";set -- $LINE
   for((i=1;i<=$#;i++))
   do
      s=$(eval echo \$${i})
      case "$s" in
         *_t* ) echo ":-> ${s##*_t}"
      esac
   done
   ;;
  esac
done <"file"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern exclusion between two files

I have a large file (file1) that has 96770154 lines and a smaller file (file2) that has 3 lines. I want to remove all of the strings from file1 that occur in file2. file1 looks like this: DOGDOGNODOGTESTCAT CATHELLOBYEEBYEFAT CATCATDOGDOGCATYESGOOD file2 looks like this: YES... (10 Replies)
Discussion started by: verse123
10 Replies

2. Shell Programming and Scripting

Separating list of input files (*.file) with a comma in bash script

Hi all, I'm trying to get a bash script working for a program (bowtie) which takes a list of input files (*.fastq) and assembles them to an output file (outfile.sam). All the .fastq files are in one folder in my home directory (~/infiles). The problem is that the 'bowtie' requires that... (7 Replies)
Discussion started by: TuAd
7 Replies

3. Shell Programming and Scripting

Separating Pattern Into Separate Files

I am trying to separate a specific pattern match into separate files. Sometimes there is only one pattern match, but other times there could be multiple (up to 6 or 8). Pattern is as follows - its starts with NYZ or VTZ and ends with $$. Again looking to get those blocks of data from one big... (17 Replies)
Discussion started by: Double-E
17 Replies

4. Shell Programming and Scripting

Awk search for string pattern in delimited file

I've got a semicolon delimited file. I would like to search for fields that match a pattern, and not hardcoded eg "mth". *th=something If the delimited field fulfills this condition, eg. mth=value I would like to print out both key and value for some number comparison. eg. if value > "12"... (5 Replies)
Discussion started by: alienated
5 Replies

5. Shell Programming and Scripting

Extract value from delimited file base on white list

I would like to use a variable to store the IDs that I would like to extract. I would like to extract a list of values of the IDs from a delimited string. Using bash here. file format would be id1=we1;id2=er2;id3=rt3;id4=yu4 The number of fields and records is not fixed. There could be... (2 Replies)
Discussion started by: milo7
2 Replies

6. Shell Programming and Scripting

Delete old files but with exclusion with file list

Hello Can you please help and check what im missing on script below the goal is to delete the old files more than 7 days old but not the excluded file list inside excluded.dat file #!/bin/sh EXCLUDE=/path/to/exclude/exclude.dat FIND=/bin/find for xfile in '(read $EXCLUDE)' do $FIND... (9 Replies)
Discussion started by: angst_nu
9 Replies

7. Shell Programming and Scripting

Merging files into a single tab delimited file with a space separating

I have a folder that contains say 50 files in a sequential order: cdf_1.txt cdf_2.txt cdf_3.txt cdf_3.txt . . . cdf_50.txt. I need to merge these files in the same order into a single tab delimited file. I used the following shell script: for x in {1..50}; do cat cdf_${x}.txt >>... (3 Replies)
Discussion started by: Lucky Ali
3 Replies

8. Shell Programming and Scripting

separating comma delimited words

Hi, I have file with text ________________________________ GROUP:firstname1.lastname1,first_name2.last_name2,first_name3.last_name3 HEAD:firstname.lastname ________________________________ I need help to pick the names separately ie.. Need out put as var1 =firstname1.lastname1... (4 Replies)
Discussion started by: rider29
4 Replies

9. UNIX for Dummies Questions & Answers

Searching a file with exclusion in the search

Hello, I'm looking for a bit of help. Im trying to search a file for lines that contain white spaces at the end of the lines. This is what I'm using where $param is the path and file name and it redirects the output to a txt file : echo | grep -n ' $' $param >> $2 Is it possible to have... (8 Replies)
Discussion started by: gintreach
8 Replies

10. Shell Programming and Scripting

Exclusion List of file and directory

dear all i trying to list all files within a directory. I want to exclude all subdirectory and some files, with using below statement, but it not exclude the files which start with "&" and end with "SL" , is there any things wrong with the below statement ? TIA cd /myaccount/mydirectory... (6 Replies)
Discussion started by: ayang
6 Replies
Login or Register to Ask a Question