How to add 'n' of tab char?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add 'n' of tab char?
# 1  
Old 06-08-2009
How to add 'n' of tab char?

Hi All,

I need to add 'n' no. of tab char (\t) in a file thro' a script. Say for example if I give 5 as input then my script should give the all the lines with 5tabs.

Input File :
#######
12323234
56465456
asdfdf456
dfgdf4564

So my Output File should look like:
#######################
\t\t\t\t\t12323234
\t\t\t\t\t56465456
\t\t\t\t\tasdfdf456
\t\t\t\t\tdfgdf4564

Thanks in advance
Saravana
# 2  
Old 06-08-2009
Code:
$
$ cat data.txt
12323234
56465456
asdfdf456
dfgdf4564
$
$ # add 4 tabs in front of each line
$ perl -ne 'print "\t" x 4,$_' data.txt
                                12323234
                                56465456
                                asdfdf456
                                dfgdf4564
$
$

tyler_durden
# 3  
Old 06-08-2009
Code:
awk -v var=5 ' { for (i=1;i<=var;i++) printf("%s","/t"); print ;}' inpfile.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a numeric & special char to end of the first line

Need to add a numeric & special char to end of the first line Existing file: 12-11-16|11 2016 Jan 12:34:55|03:55| 13-10-16|10 2016 Jan 12:34:55|03:55|12-11-16|11 2016 Jan 12:34:55|03:55| 14-10-16|19 2016 Jan 12:34:55|03:55|13-11-16|11 2016 Jan 12:34:55|04:55| 15-10-16|18 2016 Jan... (11 Replies)
Discussion started by: Joselouis
11 Replies

2. Shell Programming and Scripting

awk to add tab to output of both conditions

In the below awk written by @RavinderSingh13 I have added a few lines and am trying to have the output be tab-delimited. The input is space-delimeted and the portion in bold seems to add a tab to the Not found but not the found. Thank you :). file1 One 1 Two 2 Three 3 file2 One 1... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

How to add a new sheet or a new tab in a csv file?

Hi All, I woulk like thanks to all of you for your instant support. I am again in a trouble so move to here for solution. I want to add a new sheet or a new tab in a csv file means a singly csv file having two or more sheets. Please help me any help towards this should highly be appreciated. ... (3 Replies)
Discussion started by: Ashish Singhal
3 Replies

4. Shell Programming and Scripting

Add new line after ' char

Hello experts, I need to convert one file into readable format. Input file is like following line. STG,12345,000,999,' PQR, 2345,000,999,' XYZ,7890,000,999, Output should be following (After ' char new line char should be added.) STG,12345,000,999,' PQR, 2345,000,999,' ... (16 Replies)
Discussion started by: meetmedude
16 Replies

5. Shell Programming and Scripting

Add char before certain line

I'm trying to add a '1' before a line that has the word "C_ID" s/.*C_ID.*/&\n1/ The above code did what I need, but the '1' is added after the C_ID word :( Help please. (5 Replies)
Discussion started by: newbeee
5 Replies

6. UNIX Desktop Questions & Answers

add char o end of line if dosent exist

hey , i want to check if the char "#" exist at the end of every line of txt file and if it dosent then add it for example: the cat jumped on my mom # cars can run on water# i cant get a date blue yellow# will be: the cat went back home# cars can run on water# i cant get a... (2 Replies)
Discussion started by: boaz733
2 Replies

7. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

8. UNIX for Advanced & Expert Users

cat a field and add a char

I tried to readout the forth word of a file and add a ',' after each occurance and write the result in a file, but following code doesn't work cat output.csv | cut -d ';' -f4 || ', '>> NR.txt (2 Replies)
Discussion started by: ABE2202
2 Replies

9. UNIX for Dummies Questions & Answers

tab char appearing as single space?

I'm trying to run a script which will ssh to several other servers (All Solaris 10) and execute a sar -f command to get each server's CPU usage for a given hour. It kinda works OK but I just can't figure out how to separate the returned fields with a Tab character. I've done lots of searching... (2 Replies)
Discussion started by: jake657
2 Replies

10. Shell Programming and Scripting

how to Add Tab

How to added a TAB at end of each line of a file using ksh vi (1 Reply)
Discussion started by: ravi.sadani19
1 Replies
Login or Register to Ask a Question