Home Man
Search
Today's Posts
Register

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?

Login to Reply

 
Thread Tools Search this Thread
# 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-10-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 12: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 to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[solved] Comma separated values to space separated lost.identity UNIX for Dummies Questions & Answers 0 04-16-2013 05:59 AM
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 01:58 PM
How to loop through space separated values? kchinnam Shell Programming and Scripting 12 12-15-2011 04:19 PM
How to echo space or tab delimited values into rows? adshocker UNIX for Dummies Questions & Answers 5 07-19-2011 07:38 AM
ksh: what does x in front of something mean? JamesByars Shell Programming and Scripting 8 10-26-2010 05:11 PM
Calculate total space, total used space and total free space in filesystem names matching keyword bigben1220 Shell Programming and Scripting 4 11-25-2009 10:37 AM
Handling values with space while passing commandline argument from wrapper script in KSH kans Shell Programming and Scripting 2 10-23-2009 05:21 PM
remove space in front or end of each field happyv Shell Programming and Scripting 6 03-22-2007 02:05 AM


All times are GMT -4. The time now is 01:28 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password