Extra Space in output - remove


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extra Space in output - remove
# 1  
Old 02-03-2015
Extra Space in output - remove

Hi All

I am trying to perform the below operation -
Code:
count=`cat abc.txt | wc -l`
 
echo$count
 
5
 
Head=Start"$DATE"00000"$count"File
 
echo $HEAD
 
START15020300000 5File

There is a space coming before 5 which is not needed . How to ignore that .

Last edited by rbatte1; 02-03-2015 at 09:08 AM.. Reason: Added CODE tags
# 2  
Old 02-03-2015
Try declaring the variable count as an integer before assignment:

Code:
 
typeset -i count
count=`cat abc.txt | wc -l`
etc....

# 3  
Old 02-03-2015
Unix wc has leading spaces.
Work-around:
Code:
count=`grep -c '^' abc.txt`

or
Code:
count=`sed -n '$=' abc.txt`

or
Code:
count=`awk 'END {print NR}' abc.txt`


Last edited by MadeInGermany; 02-03-2015 at 10:51 AM..
# 4  
Old 02-03-2015
Could also simply substitute:

Code:
....
Head="Start${DATE}00000${count/ /}File"
...

hth
# 5  
Old 02-03-2015
Thanks all its working now .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

#Spool/Query executing with extra space.

Hello, I have a requirement where i have to spool some data to a file. i have achived the desired target but m facing one issue. i have attached the script and the output. i checked the data length in the table but it is only 45 for column 1. can you tell me how to remove these extra... (4 Replies)
Discussion started by: Mohammed_Tabish
4 Replies

2. Shell Programming and Scripting

[Solved] Howto remove extra space in the file

Hi Gurus, I have a file which contains some special char or space. when using cat -evt I can see the file as following: 0,"0000","abc/def aaa ... (6 Replies)
Discussion started by: ken6503
6 Replies

3. UNIX for Dummies Questions & Answers

Remove Extra Delimiter

Hi , I have file like this.. aaa|bbbb|cccc|dddd|fff|dsaaFFDFD| Adsads|sas|sa|as|asa|saddas|dsasd|sdad| dsas|dss|sss|sss|ddd|dssd|rrr|fddf| www|fff|refd|dads|fsdf|00sd| 5fgdg|dfs00|d55f|sfds55|445fsd|55ds|sdf| so I do no have any fix pattern and I want to remove extra... (11 Replies)
Discussion started by: pankajchaudhari
11 Replies

4. Shell Programming and Scripting

my shell now adds extra space at end of each line!

Hi, Since today, with csh or tcsh, if I do 'ls files* > list', every lines end with an extra space! What happenned? What can I do to go back when there was no extra space? If I change to bash, there's no extra space. Thanks, Patrick ---------- Post updated at 03:19 PM... (1 Reply)
Discussion started by: trogne
1 Replies

5. UNIX for Dummies Questions & Answers

how to remove extra characters

Guys, I have a file that contains entries like this: LaxOrdID=19220288<8> LaxOrdID=19220288 I would like to remove <> and the values inside it anywhere its found. How? (2 Replies)
Discussion started by: DallasT
2 Replies

6. Shell Programming and Scripting

Remove extra character

Hi I am using cat <filename> command in one of my datastage job(Command Activity). It is giving actual value but giving extra line. Eg: Displayed Output: 1 and showing extraline(Eg: 1 ) I had checked even wc -c it is giving one character extra. If the file contains 11. wc -c says 3. ... (3 Replies)
Discussion started by: cnrj
3 Replies

7. Shell Programming and Scripting

m4 adds extra space at top of file.

I have used m4 in the past to generate source code where aesthetics and space were of no consequence . Now I am using it to generate script and program templates . So here is an excerpt from my m4 file for producing a generic bash script: dnl `$Id$' define(`START_SCRIPT',`#!/bin/bash... (8 Replies)
Discussion started by: Bubnoff
8 Replies

8. Shell Programming and Scripting

extra space issue with awk

for diskname in $(lspv |awk '{print $1}') do lquerypv -h /dev/|awk '/'$diskname'/ { print ; exit }' done No output is returning from the loop. I think awk put an extra space to the command - lquerypv -h /dev/ so that the command is executed as i.e. lquerypv -h /dev/ hdisk230 with a space... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

9. UNIX for Dummies Questions & Answers

To remove the extra spaces in unix

Hi... I am quite new to Unix and would like an issue to be resolved. I have a file in the format below; 4,Reclaim,ECXTEST02,abc123,Harry Potter,5432 6730 0327 5469,0603,,MC,,1200,EUR,sho-001,,1,,,abc123,1223 I would like my output to be as follows; 4,Reclaim,ECXTEST02,abc123,Harry... (4 Replies)
Discussion started by: Sho
4 Replies

10. Shell Programming and Scripting

remove extra lines in the file

Hi, I have some files, with some extra lines in weird characters on the top and bottom of the. I want to get rid of those line. Is there a way I can do that? example of the input file. I want to get rid of those lines in bold  ... (8 Replies)
Discussion started by: CamTu
8 Replies
Login or Register to Ask a Question