How to add spaces to test.dat file in unix??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add spaces to test.dat file in unix??
# 8  
Old 03-17-2010
Quote:
Originally Posted by thillai_selvan
Code:
sed -i 's/\(.*\)/\1          /g' test.dat

The above sed script will add 10 space characters at the end of each lines in test.dat file.
Likewise you can add 50 spaces
You don't need to capture and use a backreference in this case. An ampersand in the replacement text will do. Also, the g flag is redundant since the pattern matches the entire line it can only match once. And, in case the original poster has any probs, note that -i requires GNU SED.
Code:
sed -i 's/.*/&          /' test.dat

Apologies if this post seemed nitpicky; I'm simply trying to help.

Regards,
Alister
# 9  
Old 03-17-2010
Try:

Code:
perl -i -lne 'print $_." "x50;' test.dat

View the file using below command to verify
Code:
cat -vet test.dat


Last edited by dennis.jacob; 03-17-2010 at 12:56 AM.. Reason: Verification instruction
# 10  
Old 03-17-2010
Quote:
Originally Posted by dennis.jacob
Try:

Code:
perl -i.bak -lne 'print $_." "x50;' test.dat

View the file using below command to verify
Code:
cat -vet test.dat

with your perl command, I got below export:

Code:
$ cat -vet output1
00:00:12,137;7,0333333                                                  ^M$
00:00:22,672;7,15                                                  ^M$
00:00:20,097;7,016667                                                  ^M$

with my awk, I got below export:

Code:
$ cat -vet output2
00:00:12,137;7,0333333                                                   $
00:00:22,672;7,15                                                   $
00:00:20,097;7,016667                                                   $

Why your perl has ^M in the file?
# 11  
Old 03-17-2010
Quote:
Originally Posted by rdcwayx
with your perl command, I got below export:

Code:
$ cat -vet output1
00:00:12,137;7,0333333                                                  ^M$
00:00:22,672;7,15                                                  ^M$
00:00:20,097;7,016667                                                  ^M$

with my awk, I got below export:

Code:
$ cat -vet output2
00:00:12,137;7,0333333                                                   $
00:00:22,672;7,15                                                   $
00:00:20,097;7,016667                                                   $

Why your perl has ^M in the file?

My file has just this out put(using your data to explain)

00:00:12,137;7,0333333
00:00:22,672;7,15
00:00:20,097;7,016667

i need to put spaces after the line to use those values as null in informatica,
# 12  
Old 03-17-2010
Quote:
Originally Posted by rdcwayx
with your perl command, I got below export:

Code:
$ cat -vet output1
00:00:12,137;7,0333333                                                  ^M$
00:00:22,672;7,15                                                  ^M$
00:00:20,097;7,016667                                                  ^M$

with my awk, I got below export:

Code:
$ cat -vet output2
00:00:12,137;7,0333333                                                   $
00:00:22,672;7,15                                                   $
00:00:20,097;7,016667                                                   $

Why your perl has ^M in the file?
Use with the chomp.

Code:
perl -i.bak -lne 'chomp;print $_." "x50;' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

How to split a dat file based on another file ni UNIX?

i have two files , one is var.txt and another res.dat file var.txt contains informaton like below date,request,sales,item 20171015,1,123456,216 20171015,1,123456,217 20171015,2,345678,214 20171015,3,456789,218 and res.dat contains is a one huge file contains information like... (1 Reply)
Discussion started by: pogo
1 Replies

2. Shell Programming and Scripting

Help with Getting distinct record count from a .dat file using UNIX command

Hi, I have a .dat file with contents like the below: Input file ============SEQ NO-1: COLUMN1========== 9835619 7152815 ============SEQ NO-2: COLUMN2 ========== 7615348 7015548 9373086 ============SEQ NO-3: COLUMN3=========== 9373086 Expected Output: (I just... (1 Reply)
Discussion started by: MS06
1 Replies

3. Shell Programming and Scripting

Date format change in UNIX .dat file

Hi, I need help to convert the date format in .DAT file in unix. I want to convert 10@@|SWIFT MT568 Extract@@|Apr 14 2014 5:47:52:563PM@@|Apr 14 2014 4:33:47:663PM@@||##| into 10@@|SWIFT MT568 Extract@@|04/14/2014/ 5:47:52:563PM@@|04/14/2014 4:33:47:663PM@@||##| Appreciate... (18 Replies)
Discussion started by: karthikengox
18 Replies

4. Shell Programming and Scripting

How to add the dat time stamp just before the last extension of a file?

hi, A file name is in the form inside a variable FILE_NAME="s1.txt.xls" i want to append date and time stamp inbetween s1.txt and .xls. so after appending date time stamp the file name would be MOD_FILE_NAME="s1.txt.201307251422.xls" currently i am using the below code... (4 Replies)
Discussion started by: Little
4 Replies

5. Shell Programming and Scripting

Conduct a search or test -f over a path with spaces

I am organizing my music library on a NAS server. I want to print a list of all the directories that are missing the cover art (at least one or more jpeg file). I have successfully created a file with each line containing the path to each occurance of one or more .mp3 files. That path is also... (2 Replies)
Discussion started by: godfreydanials
2 Replies

6. Shell Programming and Scripting

Remove <CR><LF> from the dat file in unix

Hi, The source system has created the file in the dat format and put into the linux directory as mentioned below. I want to do foloowing things. a) Delete the Line started with <CR><LF> in the record b)Also line ...........................................................<CR><LF> ... (1 Reply)
Discussion started by: mr_harish80
1 Replies

7. Shell Programming and Scripting

Performance issue in UNIX while generating .dat file from large text file

Hello Gurus, We are facing some performance issue in UNIX. If someone had faced such kind of issue in past please provide your suggestions on this . Problem Definition: /Few of load processes of our Finance Application are facing issue in UNIX when they uses a shell script having below... (19 Replies)
Discussion started by: KRAMA
19 Replies

8. UNIX for Dummies Questions & Answers

How do I delete a data string from a .dat file in unix

I have a .dat file in unix and it keeps failing file validation on line x. How do I delete a data string from a .dat file in UNIX? I tried the following: sed -e 'data string' -e file name and it telling me unrecognized command (4 Replies)
Discussion started by: supergirl3954
4 Replies

9. Shell Programming and Scripting

How to read from a .dat file in Unix

Hi All, I have a .dat file named test.dat where I have stored some process IDs. Now I need to pick a process ID, one by one and then fire kill -9 for each of those. The logic should be: 1. open file <filename.dat> 2. read until last line of file 3. if process ID is found fire kill -9... (5 Replies)
Discussion started by: Sibasish
5 Replies

10. Shell Programming and Scripting

How to attach an excel file/ dat file thru unix mails

Hi. I want to attach a .xls or .dat file while sending mail thru unix. I have come across diff attachments sending options, but allthose embeds the content in the mail. I want the attachement to be send as such. Please help me out. regards Diwakar (1 Reply)
Discussion started by: diwakar82
1 Replies
Login or Register to Ask a Question