Parse file from 2nd line in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse file from 2nd line in shell script
# 15  
Old 10-07-2010
To skip the first line:
Code:
{ read line
  while read line; do
    do stuff
  done
} < infile

# 16  
Old 10-07-2010
Hello guys,
I want to write a ksh script.
I am reading 1st line and now want to read from 2nd line onwards to get details.
Here is my code,
Code:
for file in "$INPUT_FILE_FOLDER/"AA_BB_CC*.CSV
  do
     echo ${file##*/}
     TYPE=`echo ${file##*/} | cut -d "_" -f 4`
     echo "Type is $TYPE"

            line=`head -1 $file`
	#echo "Line is : $line"
	nrfields=$(IFS=\;; set -- $line; echo $#)
	if [ $nrfields -ne 4 ]; then
	   echo "Incorrect HEADER record fields"
	else
               Date=`echo $line | cut -d ";" -f 2`
	   echo "Date is : $Date"
	   FileType=`echo $line | cut -d ";" -f 4`
	   echo "File Type is $FileType"
	fi
	
	if [ $TYPE == $FileType ]; then
	   echo "Header record is correct"
               // TO DO : read from 2nd line onwards
              // check 7th field of line
              // if its "1" then get 2nd and 4th filed values in array / variables
             // insert array value and Date value into DB table

Could you please help me with respect to this only. As I am totally confused.

Last edited by Poonamol; 10-07-2010 at 06:03 AM.. Reason: spell check
# 17  
Old 10-07-2010
Code:
for file in "$INPUT_FILE_FOLDER/"AA_BB_CC*.CSV
do
{ IFS=\; read x date x filetype x
  if [ -z "$filetype" ]; then
    echo "Incorrect HEADER record fields"
    exit 1
  fi
  echo "Date is : $date"
  echo "File Type is $filetype"
  while IFS=\; read x var2 x var4 x x var7 x
  do
    if [ $var7 -eq 1 ]; then
      echo insertintable $var2 $var4
    fi
  done
} < "$file"
done

output:
Code:
Date is : 20100913115432
File Type is NO
insertintable AAA DDD
insertintable CCC DDD


Last edited by Scrutinizer; 10-07-2010 at 06:57 AM..
# 18  
Old 10-07-2010
I need to check the Field value is 12 or not.
IF field value is 12, then only want to check the 7th field else parse next line
if both are getting (fields = 12 and status = 1) then
get the values of 2nd and 4th field.

Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SH script to parse string and return multi-line file

Hello all, I have been asked to exercise my shell scripting and it has been 10 plus years since I used to do it so I can not remember hardly anything and ask for your help. What I need to do is copy a line out of a file that can be 10 to 100 characters long, I then need to parse this line into... (3 Replies)
Discussion started by: Alivadoro
3 Replies

2. UNIX for Dummies Questions & Answers

Help to parse csv file with shell script

Hello ! I am very aware that this is not the first time this question is asked here, because I have already read a lot of previous answers, but none of them worked, so... As said in the title, I want to read a csv file with a bash script. Here is a sample of the file: ... (4 Replies)
Discussion started by: Grhyll
4 Replies

3. UNIX for Advanced & Expert Users

Shell script to parse apache httpd line

Hello, I have serveral SUN Web servers that need to write a KSH to figure out where Apache is installed and, tar up the directory (for backup purposes) once a month. The trick is that Apache is not installed in same location. So when I do "ps -ef| grep httpd" it shows on some boxes from... (2 Replies)
Discussion started by: afadaghi
2 Replies

4. Shell Programming and Scripting

Bash Shell Script to parse file

Raw Results: results|192.168.2|192.168.2.1|general/udp|10287|Security Note|For your information, here is the traceroute from 192.168.2.24 to 192.168.2.1 : \n192.168.2.24\n192.168.2.1\n\n results|192.168.2|192.168.2.1|ssh (22/tcp)|22964|Security Note|An SSH server is running on this port.\n... (2 Replies)
Discussion started by: jroberson
2 Replies

5. Shell Programming and Scripting

Parse XML file in shell script

Hi Everybody, I have an XML file containing some data and i want to extract it, but the specific issue in my file is that the data is repeated some times like the following example : <section1> <subsection1> X=... Y=... Z=... <\subsection1> <subsection2> X=... Y=... Z=...... (2 Replies)
Discussion started by: yassine
2 Replies

6. UNIX for Advanced & Expert Users

shell script to parse html file

hi all, i have a html file something similar to this. <tr class="evenrow"> <td class="data">added</td><td class="data">xyz@abc.com</td> <td class="data">filename.sql</td><td class="modifications-data">08/25/2009 07:58:40</td><td class="data">Added TK prof script</td> </tr> <tr... (1 Reply)
Discussion started by: sais
1 Replies

7. Shell Programming and Scripting

Shell script to parse a line and insert a word

Hi All, I have a file like this, data1,data2,,,data5,data6. i want to write a shell script to replace data3 with "/example/string". which means my data file should look like this . data1,data2,example/string],,data5,data6. Could you guys help me to get a sed command or any other command... (8 Replies)
Discussion started by: girish.raos
8 Replies

8. Shell Programming and Scripting

Help!!! Shell script to parse data file.

I am faced with a :confused: tricky problem to parse a data file ( May not be a tricky problem to the scripting guru's ). Here is what I am faced with. I have a file with multiple rows of data and the rows are not of fixed length. "|" is used as a delimiters for individual columns and each row... (3 Replies)
Discussion started by: yajaykumar
3 Replies

9. Shell Programming and Scripting

Parse a string in XML file using shell script

Hi! I'm just new here and don't know much about shell scripting. I just want to ask for help in creating a shell script that will parse a string or value of the status in the xml file. Please sample xml file below. Can you please help me create a simple script to get the value of status? Also it... (46 Replies)
Discussion started by: ayhanne
46 Replies

10. Shell Programming and Scripting

How to parse config variables from external file to shell script

How do i use a config.txt to recursively pass a set of variables to a shell script eg my config.txt looks like this : path=c://dataset/set1 v1= a.bin v2= b.bin path=c://dataset/set2 v1= xy.bin v2= abc.bin .................. and so on . and my testscript : (2 Replies)
Discussion started by: pradsh
2 Replies
Login or Register to Ask a Question