LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-31-2012, 07:37 AM   #1
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Rep: Reputation: Disabled
Question Trimming a String


Hi I need to trim white spaces from strings in a file.
Input file is like this:
Code:
1_rrc_CatalogGroups.csv = 607
1_rrc_Sales_TopCatalogGroups.csv = 4
1_rrc_Sales_CatalogEntries_CatalogGroup_Rel.csv = 7
Need to trim space before and after = symbol.

This is my script:
Code:
#!/usr/bin/ksh

run_count=1
catalog_name=rrc
cd /Dataload_Scripts/Files/$catalog_name
 
 # Getting row count from property file
 FILE_NAME=$run_count"_"$catalog_name"_Record_Count.prop"
#pwd
for file in $run_count"_"*.csv; do
 
 PROP_KEY=$file
 echo "PROP_KEY "$PROP_KEY
 RowCount_from_prop=`cat ${FILE_NAME} | grep "${PROP_KEY}" | cut -d'=' -f2`
 echo "RowCount_from_prop= "$RowCount_from_prop
 
 # Get row count from csv file
 RowCount_from_csv=$(awk 'END { print NR-1 }' $file )
 echo "RowCount_from_csv= "$RowCount_from_csv

if [ "$RowCount_from_csv" == "$RowCount_from_prop" ]
then
 echo "Column header count row proper"
else
 echo "Error send a mail as count is not correct in " $file
  ret_flag=1
fi
done
if [ $ret_flag -eq 1  ]; then
exit 1
else
exit 0
fi
Due to spaces I'm not able to match the correct RowCount_from_prop and RowCount_from_csv. Its giving me error due to white spaces in input file.
Any help will be appreciated.
Thanks

Last edited by sukhdip; 01-31-2012 at 07:45 AM.
 
Old 01-31-2012, 07:55 AM   #2
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 360

Rep: Reputation: 40
Could you just sed the string?

Code:
cat myfile | sed -i "s/ = /=/g" myfile

Last edited by thund3rstruck; 01-31-2012 at 08:00 AM.
 
Old 01-31-2012, 07:58 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
Would this work ?
Code:
RowCount_from_prop=`awk -F' ?= ?' "/${PROP_KEY}/ {print $2}" ${FILE_NAME}`
 
  


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
[SOLVED] Trimming down Slack's fat bonixavier Slackware 5 12-19-2010 07:25 AM
About trimming a variable ahmedb72 Linux - Newbie 3 07-13-2009 06:36 AM
Trimming a installed kernel fibster Slackware 3 11-01-2006 06:47 PM
Trimming down a Suse 9.0 install Bradless Linux - Distributions 0 08-02-2004 05:36 PM
Trimming a file james_cwy Linux - Newbie 4 01-13-2004 11:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:20 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration