read a part of information from txt and put into the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read a part of information from txt and put into the script
# 8  
Old 10-24-2006
Quote:
Originally Posted by anbu23
Code:
cat list10.txt | grep -v _9_4_bfmh.archived | grep -v _orig.archived | sort |
awk ' BEGIN { flag = "y" }
{ if(str != substr($0,1,13)) 
  {
	if ( flag == "n" ) print str " is no missing"
  	str = substr($0,1,13);
	seq = substr($0,14,5);
	flag = "n"
  }
  else
  {	
	seq1 = substr($0,14,5)
	seq = int(seq) + 1;
	if( seq != int(seq1) )
	{
	flag="y"
	  while( seq++ != int(seq1) )
	  {
		printf("%s%05d%s\n", substr($0,1,13), seq, " is missing")				
	  }
	}
  }
}'

the above code is not work... Smilie
# 9  
Old 10-24-2006
Can you show whats there in the list10.txt file ?
# 10  
Old 10-25-2006
list10.txt is grep from the directory of all need files and write into list10.txt:

CDBACKUPJOHN100001.archived
CDBACKUPJOHN100002.archived
CDBACKUPJOHN100004.archived
CDBACKUPMARRY00381.archived
CDBACKUPMARRY00382.archived
CDBACKUPMARRY00383.archived
CDBACKUPPETER01101.archived
CDBACKUPPETER01102.archived
CDBACKUPPETER01105.archived
# 11  
Old 10-25-2006
try this
Code:
awk ' BEGIN { flag = "y" }
{ if(str != substr($0,1,13))
  {
        if ( flag == "n" ) print str " is no missing"
        str = substr($0,1,13);
        seq = substr($0,14,5);
        flag = "n"
  }
  else
  {
        seq1 = substr($0,14,5)
        seq = int(seq) + 1;
        if( seq != int(seq1) )
        {
        flag="y"
          while( seq != int(seq1) )
          {
                printf("%s%05d%s\n", substr($0,1,13), seq, " is missing")
                seq = int(seq) + 1;
          }
        }
  }
}'

# 12  
Old 10-25-2006
Hi, but the output....is not correct, it will keep display mssing from 0001...and like a loop...cannot end.

Also, I only would like to show the jumping seq (because of the first file in the list may start from any number such as 00421 and end number is 00435. Then the script will check between 00421 and 00435 of jumping seq).

00001 is missing
00002 is missing
00003 is missing
00004 is missing
00005 is missing
00006 is missing
00007 is missing
00008 is missing
00009 is missing
00010 is missing
00011 is missing
00012 is missing
00013 is missing
00014 is missing
00015 is missing
00016 is missing
00017 is missing
00018 is missing
00019 is missing
00020 is missing
00021 is missing
00022 is missing
00023 is missing
00024 is missing
00025 is missing
.
.
.

Please help..Many..Many Thanks!!
# 13  
Old 10-26-2006
it look like the loop not read the list.txt

#!/bin/sh
/bin/rm result_list.txt
while read name
do
ls -1 /appl/CH_DATA/archive/00000/CACHE/${name}*.archived | grep -v _9_4_bfmh.archived | grep -v _orig.archived >> result_list.txt
done <need_to_search.txt
cat result_list.txt
awk ' BEGIN { flag = "y" }
{ if(str != substr($0,1,46))
{
if ( flag == "n" ) print str " is no missing"
str = substr($0,1,46);
seq = substr($0,47,5);
flag = "n"
}
else
{
seq1 = substr($0,47,5)
seq = int(seq) + 1;
if( seq != int(seq1) )
{
flag="y"
while( seq != int(seq1) )
{
printf("%s%05d%s\n", substr($0,1,46), seq, " is missing")
seq = int(seq) + 1;
}
}
}
}'

the result_list.txt is:
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00627.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00629.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00630.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00631.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00632.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00633.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00634.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00635.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00636.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00656.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00657.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00658.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPMARY01818.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPMARY01820.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPMARY01821.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPMARY01822.archived
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPMARY01823.archived
# 14  
Old 10-26-2006
Code:
#!/bin/sh
/bin/rm result_list.txt
while read name
do
ls -1 /appl/CH_DATA/archive/00000/CACHE/${name}*.archived | grep -v _9_4_bfmh.archived | grep -v _orig.archived >> result_list.txt
done <need_to_search.txt
cat result_list.txt |
awk ' BEGIN { flag = "y" }
{ if(str != substr($0,1,46))
{
if ( flag == "n" ) print str " is no missing"
str = substr($0,1,46);
seq = substr($0,47,5);
flag = "n"
}
else
{
seq1 = substr($0,47,5)
seq = int(seq) + 1;
if( seq != int(seq1) )
{
flag="y"
while( seq != int(seq1) )
{
printf("%s%05d%s\n", substr($0,1,46), seq, " is missing")
seq = int(seq) + 1;
}
}
}
}'

Output:

Code:
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00628 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00637 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00638 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00639 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00640 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00641 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00642 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00643 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00644 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00645 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00646 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00647 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00648 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00649 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00650 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00651 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00652 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00653 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00654 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPJOHN00655 is missing
/appl/NA_DATA/archive/00000/CACHE/CDBACKUPMARY01819 is missing

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

3. Shell Programming and Scripting

Needed shell script to read txt file and do some modification

Hi ...programmers... I need a shell script to perform some specific task.. my txt file looks like this netcdf new { dimensions: XAX1_11 = 11 ; variables: double XAX1_11(XAX1_11) ; XAX1_11:point_spacing = "even" ; XAX1_11:axis = "X" ; float DEPTH(XAX1_11) ;... (19 Replies)
Discussion started by: Akshay Hegde
19 Replies

4. Shell Programming and Scripting

Please Help! Need to put the lines of a txt to one line

Hi all, I'm quite newbie in shell scripting but I found a problem what I cant solve. I have a .txt file which looks like this: /22/ /23/ /24/ and so on and I'd need to make it look like this: /22/|/23/|/24/|...and so on. these numbers are growing and has lines like this /2a/ as well.... (15 Replies)
Discussion started by: gergo235
15 Replies

5. Shell Programming and Scripting

how to read strings from a txt and put them into a spreadsheet?

i have hundreds of thousands of txt files as below, RADARSAT 1 SCENE DESCRIPTION SCENE_ID c0005098 MDA ORDER NUMBER GEOGRAPHICAL AREA CIS ScanSar Canada SCENE START TIME APR 02 1997 23:05:10.222 SCENE STOP TIME APR 02 1997 23:02:49.695... (5 Replies)
Discussion started by: sunnydanniel
5 Replies

6. Shell Programming and Scripting

How to read userid and password information from txt file

Hi Experts, I am writing a shell script (for displaying disk space details) which is logging to 15 different servers using following command. ssh userid@servername It is prompting me for password for all 15 servers when I manually run it. However , soon I would like to schedule this script... (4 Replies)
Discussion started by: ajaypatil_am
4 Replies

7. Programming

extracting information from lines, put them into arrays

hi I need a little help writing this small perl script. I'm trying to extract the values from each line in a file and find the average for example cat school Highschool 100, 123, 135 Middleschool 41, 67, 54 Elementary 76, 315, 384 ./average.pl highschool: 119.3 middleschool: 54... (2 Replies)
Discussion started by: gengar
2 Replies

8. Shell Programming and Scripting

Extract zip code information from address, put into new column

Hi, suppose I have a colon delimeterd file with address field like this blue:john's hospital new haven CT 92881-2322 yellow:La times copr red road los angeles CA90381 1302 red:las vegas hotel sand drive Las vegas NV,21221 How do I create a new field that contain the zip code information... (3 Replies)
Discussion started by: grossgermany
3 Replies

9. Shell Programming and Scripting

sed to read x.txt and grep from y.txt

How would I write a command(s) to read from a file (list) that looks like this: 29847374384 and grep from a second file (list) that looks like this: 29847374384, jkdfkjdf,3833,ddd:confused: (1 Reply)
Discussion started by: smellylizzard
1 Replies

10. Shell Programming and Scripting

read a part of filename from the list in the script

how can i read a part of filename from the list in the script? all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number. CDBACKUPFILEJOHN00001 CDBACKUPFILEMARRY00004 CDBACKUPFILEPETER00003 I will use:... (3 Replies)
Discussion started by: happyv
3 Replies
Login or Register to Ask a Question