LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-25-2011, 02:14 PM   #1
smritisingh03
Member
 
Registered: Nov 2010
Posts: 43

Rep: Reputation: 0
need to cut fields


hi

the sample of input file is :

Quote:
ACCOUNT_MISSING-4 ACCOUNT_MISSING- is missing
ADP_COMMENT-2311 ADP_COMMENT- 2384
ADP_CONFIG-11 ADP_CONFIG- 11
ADP_FIELD-36323 ADP_FIELD- 36333
I need to cut each field and store in varibles.

example: tablename1= ACCOUNT_MISSING

count1=4

tablename2= ACCOUNT_MISSING

count1=is missing

what I have tried is:

Quote:
#!/bin/ksh





paste -d ' \ ' logcountOP DBcountOP400 > differencenewOP



export file="differencenewOP"

while read FILE_LINE ; do

LINE1="$(echo $FILE_LINE | cut -d ' ' -f1)"
tablename1="$(echo $LINE1 | cut -d '-' -f1)"

echo tablename1 is $tablename1

count1="$(echo $FILE_LINE | cut -d '-' -f2)"

echo count1 is $count1

LINE2="$(echo $FILE_LINE | cut -d ' ' -f3)"
tablename2="$(echo $LINE2 | cut -d '-' -f1)"
count2="$(echo $LINE2 | cut -d ' ' -f2)"

echo tablename2 is $tablename2

echo count2 is $count2

if [ $count1 = "is" ]

then

echo missing

echo status for $tablename1- does not exist in DB >> statusOP

elif [ $count1 -eq $count2 ]

then
#echo match

echo status for $tablename2 $count2 $count1- match >> statusOP

elif [ $count1 -ne $count2 ]

then

#echo mismatch



echo status for $tablename2 $count2 $count1- mismatch >> statusOP


fi

done < $file


please help
 
Old 01-25-2011, 02:49 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Too many cut commands for my taste. Here is an alternative using awk and reading 4 variables in a loop:
Code:
while read tablename1 count1 tablename2 count2
do
  your commands here
done <(awk -F "[- ]" '{print $1, $2, $3, $5, $6}' $file)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I cut fields with repeated delimiters? Mountain Linux - Software 4 11-19-2012 07:50 AM
Separating Fields from Output - cut command Hi_This_is_Dev Linux - General 3 08-28-2010 02:23 PM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 07:16 PM
cut fields in a file christina_rules Linux - Newbie 12 07-15-2006 10:00 AM


All times are GMT -5. The time now is 03:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration