How to add space in front of cat values?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to add space in front of cat values?
# 1  
Old 10-10-2017
How to add space in front of cat values?

Hi,

Hope you are all doing fine.

The problem today i faced during my coding was i wanted to add a space equals to a tab character in front of all the lines which i am cat using tee command.

Main file contents

mainfile
Code:
1,/level1/level2/CAP_data.171002/20171002_060344_53608614,20171002_060344_53608614
2,/level1/level2/20171005_023901_56688702,20171005_023901_56688702
3,/level1/level2/20171005_023903_13697660,20171005_023903_13697660
4,/level1/level2/20171005_023905_33947650,20171005_023905_33947650
5,/level1/level2/20171005_023906_11666112,20171005_023906_11666112
6,/level1/level2/20171005_023908_49545338,20171005_023908_49545338
7,/level1/level2/20171005_023911_18875126,20171005_023911_18875126
8,/level1/level2/20171005_023913_36372644,20171005_023913_36372644
9,/level1/level2/20171005_023915_3539570,20171005_023915_3539570

Code:
cat $mainfile  | tee -a $log

I am actually cat'ting the file content to a user menu and a log file i want to add space in front of all the lines shown above it should be regardless of the no of lines in the file content!!
like below snap shot.

Code:
	1,/level1/level2/CAP_data.171002/20171002_060344_53608614,20171002_060344_53608614
	2,/level1/level2/20171005_023901_56688702,20171005_023901_56688702
	3,/level1/level2/20171005_023903_13697660,20171005_023903_13697660
	4,/level1/level2/20171005_023905_33947650,20171005_023905_33947650
	5,/level1/level2/20171005_023906_11666112,20171005_023906_11666112
	6,/level1/level2/20171005_023908_49545338,20171005_023908_49545338
	7,/level1/level2/20171005_023911_18875126,20171005_023911_18875126
	8,/level1/level2/20171005_023913_36372644,20171005_023913_36372644
	9,/level1/level2/20171005_023915_3539570,20171005_023915_3539570

Kindly help me out for this.
# 2  
Old 10-10-2017
Not sure I totally follow. Some punctuation would not go a miss ;-)

Code:
$ sed "s/^/  /" t.txt
  1,/level1/level2/CAP_data.171002/20171002_060344_53608614,20171002_060344_53608614
  2,/level1/level2/20171005_023901_56688702,20171005_023901_56688702
  3,/level1/level2/20171005_023903_13697660,20171005_023903_13697660
  4,/level1/level2/20171005_023905_33947650,20171005_023905_33947650
  5,/level1/level2/20171005_023906_11666112,20171005_023906_11666112
  6,/level1/level2/20171005_023908_49545338,20171005_023908_49545338
  7,/level1/level2/20171005_023911_18875126,20171005_023911_18875126
  8,/level1/level2/20171005_023913_36372644,20171005_023913_36372644
  9,/level1/level2/20171005_023915_3539570,20171005_023915_3539570

(no need for cat)
# 3  
Old 10-10-2017
Should those "spaces" occur in both the user menu and the log file, or, if not, in which of them?
# 4  
Old 10-11-2017
This will insert a TAB at the beginning.

Code:
cat  $mainfile  | xargs -i echo "\t{}" | tee -a  $logfile


Last edited by Scott; 10-11-2017 at 01:54 AM.. Reason: Code tags...
# 5  
Old 10-11-2017
Hi All,

Thank you for all your reply i tried all the solutions given here but not fruitful.
I ended up in while loop for this issue and it is working.

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add text in front of variable

I am just trying to add specific text in front of a ${variant} but can not seem to get the syntax correct. I have tried sed -i '$a NM_004004.5' ${variant} and printf "NM_004004.5:%s\n" ${variant} with no luck. Thank you :). (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Linux

How to add \ in front of $ in a script with vi?

Please help to provide command in vi to add \ in front of $ so it does not interpret next character. rm interfaces/DART/WEB-INF/classes/DART/util/TotalDisconnectUtil$1.class rm interfaces/DART/WEB-INF/classes/DART/util/TotalDisconnectUtil$2.class rm... (3 Replies)
Discussion started by: ywu081006
3 Replies

3. Shell Programming and Scripting

Moving cat values to a variable

I have a file created as ABC!DEF@2014.txt My if condition is based on 2014 so I need to move it to variable. So while I can do this on console screen - ls ABC* -l > test.txt cat test.txt | cut -f 2 -d "@" | cut -f 1 -d "." to get the value - 2014 I am a bit at loss how to achieve this... (4 Replies)
Discussion started by: rajiv_kool
4 Replies

4. Shell Programming and Scripting

Want non-interpretation of blank space using cat

I have a file say ADCD which is like following--> Please consider 'z' as space #cat ADCD <!--Yzzz|z--> <!--Nzzzzz--> Now I want to store the content of this file to a variable say VAR like this--> #VAR=`cat ADCD` #echo $VAR <!--Yz|z--> <!--Nz--> Now I don' t want the variable... (2 Replies)
Discussion started by: muchyog
2 Replies

5. Shell Programming and Scripting

Cat Values from Several files if it meets criteria for column values

I have results from some statistical analyses. The format of the results are as given below: I want to select lines that have a p-value (last column) less than 0.05 from all the results files (*.results) and cat to a new results file. It would be very nice if a new column is added that tells... (2 Replies)
Discussion started by: genehunter
2 Replies

6. Shell Programming and Scripting

How join line and add | in front

Hello, Did any one know how to use perl join line and add | in front Input--> timestamp=2009-11-10-04.55.20.829347; a; b; c; ddaa; timestamp=2009-11-10-04.55.20.829347; aa; bb; cc; Output--> ... (2 Replies)
Discussion started by: happyday
2 Replies

7. Shell Programming and Scripting

problem in using cat and ended up with no space error in aix

While doing cat on a large file (3 GB file) , I am getting the no space error in the shell script hugefile.sh. Eg: for i in `cat hugefile.txt` do echo "$i" done error: hugefile.sh: no space Please let me know your thoughts in handling this no space issue. (2 Replies)
Discussion started by: techmoris
2 Replies

8. Shell Programming and Scripting

Have a basic 'for i in cat list' - Trying to get i to be set to a name with a space

Hi Have a file called ldap.list: ****** "o=unix forum" o=groups ****** i wrote a basic script that runs: for i in `cat ldap.list` do ldapsearch -h host -p 389 -b $i THE PROBLEM: - It looks like when the for i in cat ldap.list runs, it doesn't seem to care about the " ", it... (2 Replies)
Discussion started by: littlefrog
2 Replies

9. Shell Programming and Scripting

remove space in front or end of each field

Hi, I have a txt file called a.txt which contain over 10,000 records and I would like to remove space before comma or after comma....like below: The input (for example two record 00001,00002): 00001,client,card limited ,02292,N ,162:41 , 192, ... (6 Replies)
Discussion started by: happyv
6 Replies

10. UNIX for Dummies Questions & Answers

cat: write error: No space left on device

I am trying to create new files under my directory...but i getting the following message... cat: write error: No space left on device How do we handle this error. I am not getting this error when I login as the super user (3 Replies)
Discussion started by: igandu
3 Replies
Login or Register to Ask a Question

Featured Tech Videos