How to label a specific file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to label a specific file
# 1  
Old 05-24-2008
How to label a specific file

Hi, All,

I have a file, it looks like:

"TEST/DR1/FELC0/SI1386.rec"
0 1513 !ENTER 1513
1513 2994 q 1481
2994 4440 iy 1446
4440 5080 v 640
5080 6266 ih 1186
6266 7436 n 1170
7436 10360 eh 2924
10360 12338 !EXIT 1978
"TEST/DR1/FELC0/SI138.rec"
0 2120 !ENTER 2120
2120 2725 q 605
2725 3212 ao 487
3212 3533 r 321
3533 4530 bcl 997
4530 4780 !EXIT 250

each line starts with "TEST/DR1" is a file name, and the following lines are its contents. for each file, if its fourth column has a value is less than 500, then a flag 1 is set at the end of the file name, otherwise, set 0.

after operation, the file looks like:
"TEST/DR1/FELC0/SI1386.rec" 0
0 1513 !ENTER 1513
1513 2994 q 1481
2994 4440 iy 1446
4440 5080 v 640
5080 6266 ih 1186
6266 7436 n 1170
7436 10360 eh 2924
10360 12338 !EXIT 1978
"TEST/DR1/FELC0/SI138.rec" 1
0 2120 !ENTER 2120
2120 2725 q 605
2725 3212 ao 487
3212 3533 r 321
3533 4530 bcl 997
4530 4780 !EXIT 250

Could anyone tell me how I can implement this? Thanks in advance.
# 2  
Old 05-24-2008
Code:
awk -F'[/.]'  '/^"TEST\/DR1/{ c=substr($4,3)+0; if (c<500) print $0, 1; else print $0, 0 }!/^"TEST\/DR1/'  filename

# 3  
Old 05-24-2008
Quote:
Originally Posted by rubin
Code:
awk -F'[/.]'  '/^"TEST\/DR1/{ c=substr($4,3)+0; if (c<500) print $0, 1; else print $0, 0 }!/^"TEST\/DR1/'  filename

Thanks for your help.

It works for this example, but when I change the threshold from 500 to 200, it does not work.
# 4  
Old 05-25-2008
It should work for 200 too, change 500 to 200 inside the previous code. If you're planning to have a different test number , then you might try this:

Code:
awk -v num=200 -F'[/.]'  '/^"TEST\/DR1/{ c=substr($4,3)+0; if (c < num) print $0, 1; else print $0, 0 }!/^"TEST\/DR1/' filename

Change num to whatever value you need.
# 5  
Old 05-25-2008
Quote:
Originally Posted by rubin
It should work for 200 too, change 500 to 200 inside the previous code. If you're planning to have a different test number , then you might try this:

Code:
awk -v num=200 -F'[/.]'  '/^"TEST\/DR1/{ c=substr($4,3)+0; if (c < num) print $0, 1; else print $0, 0 }!/^"TEST\/DR1/' filename

Change num to whatever value you need.
what I got is
"TEST/DR1/FELC0/SI1386.rec" 0
0 1513 !ENTER 1513
1513 2994 q 1481
2994 4440 iy 1446
4440 5080 v 640
5080 6266 ih 1186
6266 7436 n 1170
7436 10360 eh 2924
10360 12338 !EXIT 1978
"TEST/DR1/FELC0/SI138.rec" 1
0 2120 !ENTER 2120
2120 2725 q 605
2725 3212 ao 487
3212 3533 r 321
3533 4530 bcl 997
4530 4780 !EXIT 250

but it is supposed to be
"TEST/DR1/FELC0/SI1386.rec" 0
0 1513 !ENTER 1513
1513 2994 q 1481
2994 4440 iy 1446
4440 5080 v 640
5080 6266 ih 1186
6266 7436 n 1170
7436 10360 eh 2924
10360 12338 !EXIT 1978
"TEST/DR1/FELC0/SI138.rec" 0
0 2120 !ENTER 2120
2120 2725 q 605
2725 3212 ao 487
3212 3533 r 321
3533 4530 bcl 997
4530 4780 !EXIT 250
# 6  
Old 05-25-2008
Quote:
Originally Posted by Jenny.palmy
for each file, if its fourth column has a value is less than 500, then a flag 1 is set at the end of the file name, otherwise, set 0.
SI138 is SI 138 which is smaller than 200 or 500, and the flag should be 1 as per your initial requirement.
Code:
"TEST/DR1/FELC0/SI138.rec" 1

# 7  
Old 05-25-2008
Quote:
Originally Posted by rubin
It should work for 200 too, change 500 to 200 inside the previous code. If you're planning to have a different test number , then you might try this:

Code:
awk -v num=200 -F'[/.]'  '/^"TEST\/DR1/{ c=substr($4,3)+0; if (c < num) print $0, 1; else print $0, 0 }!/^"TEST\/DR1/' filename

Change num to whatever value you need.
sorry, I think there is misunderstanding. for the original file

"TEST/DR1/FELC0/SI1386.rec"
0 1513 !ENTER 1513
1513 2994 q 1481
2994 4440 iy 1446
4440 5080 v 640
5080 6266 ih 1186
6266 7436 n 1170
7436 10360 eh 2924
10360 12338 !EXIT 1978
"TEST/DR1/FELC0/SI138.rec"
0 2120 !ENTER 2120
2120 2725 q 605
2725 3212 ao 487
3212 3533 r 321
3533 4530 bcl 997
4530 4780 !EXIT 250

for threshold 500, the executed file should looks like

"TEST/DR1/FELC0/SI1386.rec" 0
0 1513 !ENTER 1513
1513 2994 q 1481
2994 4440 iy 1446
4440 5080 v 640
5080 6266 ih 1186
6266 7436 n 1170
7436 10360 eh 2924
10360 12338 !EXIT 1978
"TEST/DR1/FELC0/SI138.rec" 1
0 2120 !ENTER 2120
2120 2725 q 605
2725 3212 ao 487
3212 3533 r 321
3533 4530 bcl 997
4530 4780 !EXIT 250

because the following lines in file "TEST/DR1/FELC0/SI138.rec"

3212 3533 r 321
4530 4780 !EXIT 250
the fourth column less than 500
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to update specific value in file with match and add +1 to specific digit

I am trying to use awk to match the NM_ in file with $1 of id which is tab-delimited. The NM_ will always be in the line of file that starts with > and be after the second _. When there is a match between each NM_ and id, then the value of $2 in id is substituted or used to update the NM_. Each NM_... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

3. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

4. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

5. Shell Programming and Scripting

Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as (7 Replies)
Discussion started by: manigrover
7 Replies

6. Shell Programming and Scripting

Urgent request to consider:Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as # Drug_Target_X_Gene_Name:(Where X can be any number (1-1000) (1 Reply)
Discussion started by: manigrover
1 Replies

7. UNIX for Advanced & Expert Users

allow user to use sudo cp on a specific directory and only a specific file

Is there a way to allow a user to use sudo cp on a specific directory and only a specific file? (6 Replies)
Discussion started by: cokedude
6 Replies

8. Shell Programming and Scripting

How to copy specific file.txt in specific folder?

hye there... i have a problem to copy file in specific folder that will change the name according to host,time(%m%s) and date(%Y%M%D) example folder name: host_20100531.154101801 this folder name will always change... but i just want to copy the AAA.txt and BBB.txt file.. really need... (17 Replies)
Discussion started by: annetote
17 Replies

9. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

10. Solaris

Help:"Bad checksum in disk label" and "Can't open disk label package"?

Hello, I'm brand new to Sun/Solaris. I have a Sun Blade 150, with SunOS 5.8. I wanted to make a backup to prevent future data loss, so I put the disk in a normal PC with Windows XP to try to make a backup with Norton Ghost, the disk was detected, but not the file volume, so I place the disk... (6 Replies)
Discussion started by: Resadija
6 Replies
Login or Register to Ask a Question