Trimming a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trimming a string
# 1  
Old 01-31-2012
Network 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 08:46 AM..
# 2  
Old 01-31-2012
Can you not use sed?

Code:
sed 's/ = /=/g'  oldfile > newfile
# next run your script
./myscript.sh

# 3  
Old 01-31-2012
thanks ..
but i solved it this way
Code:
tr -d '" "'

So for working fine....

Regards,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Trimming ends

My files look like this I need to remove the sequence GGGAAA and anything before that I also need to remove the sequence AGCCCTA and anything after that So I will end up with something like this The left side is done but I cannot get the right side correctly. I would like to use... (3 Replies)
Discussion started by: Xterra
3 Replies

2. Shell Programming and Scripting

Trimming in between the words

Hi i have a log file P12345_15728710:DEBUG:Begin P12345_15728710:DEBUG:Being P12345_15729310:DEBUG:GetAgen P12345_15726510:DEBUG:end i want to trim this file and i want like this 15728710 15728710 15729310 15726510 i tried sed ..but not working.. sed "s/.*P12345__ \(.*\)... (4 Replies)
Discussion started by: navsan420
4 Replies

3. UNIX for Dummies Questions & Answers

awk for trimming a string up to the first, then second, then third... match

Hi ! With awk, I would need to trim a string from the beginning up to the first occurrence of "1", then from the beginning up to the second occurrence of "1", then from the beginning up to the third, then the fourth...., then the last occurrence of "1". input: 1aaa1bb1ccccccc dd1e1ffff... (7 Replies)
Discussion started by: beca123456
7 Replies

4. UNIX for Dummies Questions & Answers

Trimming a string based on delimiter.

Hi, I have a string say "whateverCluster". I need everthing apart from the string "Cluster" Input: whateverCluster Desired output: whatever (5 Replies)
Discussion started by: mohtashims
5 Replies

5. Shell Programming and Scripting

Trimming output

I'm trying to parse an output log and I've managed to reduce the output to the lines I need. But I'm having trouble pulling out only the info I'm interested in. The output is 40+ lines and here is a sample Installing AppFresh 0.8.5.pkg from ./InstallerFiles/CustomPKG/26 (26) Installing... (2 Replies)
Discussion started by: kaltekar
2 Replies

6. Shell Programming and Scripting

trimming lines

hi have output as i have trim of lines before CREATE statement and lins after last ")" any idea how to achieve it ? (3 Replies)
Discussion started by: crackthehit007
3 Replies

7. UNIX for Advanced & Expert Users

Trimming the spaces

Hi, How can I remove the unwanted spaces in the line. 123456 789 ABC DEF. - I wanna remove the sapces in this line, I need the output 123456789ABCDEF. Pls help me...... (3 Replies)
Discussion started by: sharif
3 Replies

8. UNIX for Advanced & Expert Users

trimming zeros

Hi, I want to trim +with leading zero's with amount fields.I know using awk for trimming leading zeros with +,but I want get the entire row itself. cat file_name |awk -F " " '{printf "%14.4f%f\n",$4}' ex: 10 xyz bc +00000234.4500 20 yzx foxic +002456.000 Expexted 10 xyz bc... (3 Replies)
Discussion started by: mohan705
3 Replies

9. Shell Programming and Scripting

Trimming a string

Hi, I am trying to find a script command that will let me trim leading and trailing space from a string. I have coded a SQL Select and sending the output to a file. Later I am parsing the file and reading each field. The problem is that each field uses the same size as the DB2 type it was defined... (2 Replies)
Discussion started by: fastgoon
2 Replies

10. UNIX for Dummies Questions & Answers

trimming a file...

Hi everyone I have this script that appends a line to a file to log the running status of an application. I need to write another script to run as a scheduled job in cron to trim the first x number of lines of this file. Could someone give me an idea how to do this? Regards (1 Reply)
Discussion started by: alwayslearningunix
1 Replies
Login or Register to Ask a Question