Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

How to add space in front of cat values?

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-10-2017   -   Original Discussion by mad man
mad man mad man is offline
Registered User
 
Join Date: Nov 2015
Last Activity: 31 October 2017, 8:11 AM EDT
Posts: 49
Thanks: 25
Thanked 1 Time in 1 Post
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.
Sponsored Links
    #2  
Old Unix and Linux 10-10-2017   -   Original Discussion by mad man
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 18 November 2017, 4:19 PM EST
Location: Zürich
Posts: 8,821
Thanks: 366
Thanked 1,196 Times in 1,022 Posts
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)
Sponsored Links
    #3  
Old Unix and Linux 10-10-2017   -   Original Discussion by mad man
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 18 November 2017, 12:12 PM EST
Location: Aachen, Germany
Posts: 11,622
Thanks: 320
Thanked 3,615 Times in 3,320 Posts
Should those "spaces" occur in both the user menu and the log file, or, if not, in which of them?
    #4  
Old Unix and Linux 10-11-2017   -   Original Discussion by mad man
garydeena garydeena is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 15 October 2017, 8:34 PM EDT
Posts: 16
Thanks: 0
Thanked 3 Times in 3 Posts
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...
Sponsored Links
    #5  
Old Unix and Linux 10-11-2017   -   Original Discussion by mad man
mad man mad man is offline
Registered User
 
Join Date: Nov 2015
Last Activity: 31 October 2017, 8:11 AM EDT
Posts: 49
Thanks: 25
Thanked 1 Time in 1 Post
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.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting rows from a space delimited text file based on the values of a column evelibertine UNIX for Dummies Questions & Answers 2 02-17-2012 02:58 PM
How to loop through space separated values? kchinnam Shell Programming and Scripting 12 12-15-2011 05:19 PM
How to echo space or tab delimited values into rows? adshocker UNIX for Dummies Questions & Answers 5 07-19-2011 08:38 AM
Handling values with space while passing commandline argument from wrapper script in KSH kans Shell Programming and Scripting 2 10-23-2009 06:21 PM
remove space in front or end of each field happyv Shell Programming and Scripting 6 03-22-2007 03:05 AM



All times are GMT -4. The time now is 05:21 PM.