post-Adding character for a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting post-Adding character for a text file
# 1  
Old 11-04-2011
post-Adding character for a text file

Code:
####################################################################
#NAME			SL.NO		TITLE			SAL
####################################################################
|RAGAV S S          |   12358 |    SALES EXECUTIVE|         |   25000
|RAJU R B           |   64253 |    SALES EXECUTIVE|         |   28000
|RUKMAN S           |   32588 |    SALES EXECUTIVE|         |   40000
|NARGUND S S        |   12356 |    SALES EXECUTIVE|         |   50000

Somehow I was looking for similar kind of stuff.
Can anyone assist me how to skip any headers for that text file while adding any special character in-between the columns ???
# 2  
Old 11-04-2011
You can specify an address for the command, e.g. any line that does not begin with #:
Code:
sed "/^[^#]/ s/^\(.\{19\}\)\(.\{9\}\)\(.\{19\}\)\(.\{9\}\)\(.*\)$/|\1|\2|\3|\4|\5 |/" infile

# 3  
Old 11-04-2011
Thanks a lot.
I think I'm somehow messing around my requirement
let me put it in some other way

I have a script which will prompt user for entering the values and then
each values will be written in another file with fixed starting positions.
let say

Code:
it prompt for user name : AAA
and then dept. Name: Programming IT Dept
and sal:2000E

Code:
1st  columnlength 50 and second columnlength is 75 and 3rd one is 10
So in my o/p txt 
AAA<47 - length of AAA of spaces>Programming IT Dept<75 -length of dept of spaces>2000E<10-length of sal of spaces>next line
xyxzmna<47 - length of name of spaces> etc..

I mean I have fixed length of column and eeach parameter should be fitted in that length . it's for proper alignment.

I posted in this post as there could be some link to my requirement and existing one.

---------- Post updated at 09:03 AM ---------- Previous update was at 08:29 AM ----------

Kindly ignore this question .
As the rule states not to post other question inside a question even though they might look similar or behave similar.
So I will be creating a new one, respecting the rule and regulations.
# 4  
Old 11-04-2011
Hijacking a thread of one of your counterparts is not very nice...even if there are similitudes in the demand...
You are to be owner of your own thread, nothing stopping you to add a links to the almost similar question, its ours to then explain the differences...
This is your new thread since I moved out the posts... I let you change the title
# 5  
Old 11-04-2011
To output fixed length strings you can use printf, e.g.:
Code:
# a=1; b="some text"; c="some more text"; printf "%03d %-20s %20s\n" $a "$b" "$c"
001 some text                  some more text

# 6  
Old 11-04-2011
thanks a lot Carol.
I had already this one.

But what exactly I was looking for is a dynamic one which will substact the length of column specified to the length of character and fill the unwanted one with the spaces and do the same for all the parameters anf go on. Anyway It's look like much complicated . I will do the one which I already had and you suggested.

In this way you need to count the string postions but above way , you don't have to worry specify the length of each columns and then enter the values and script will automatically populate according to the position and reformat your columns in a nice way.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo to file using SH without adding newline character

Hello! I am able to do this in bash, using: echo -ne HELLO > file.txt and then, 'HELLO' is written into file.txt without the newline character to be added in the end of the file. How is this possible to be done using sh instead of bash? If I try something similar is SH, then inside... (3 Replies)
Discussion started by: hakermania
3 Replies

2. Shell Programming and Scripting

Adding a "|" character for a text file

Dear Sir, I am having text file with no delimiter like below RAGAV S S 12358 SALES EXECUTIVE 25000 RAJU R B 64253 SALES EXECUTIVE 28000 RUKMAN S 32588 SALES EXECUTIVE 40000 NARGUND S S 12356 ... (3 Replies)
Discussion started by: suryanarayana
3 Replies

3. Shell Programming and Scripting

sort file adding extra character

HI all i have this script : #!/bin/bash sort /usr/tmp/"REPORT"$1 -o \ /usr/tmp/"SREPORT"$1 -k 1,7 -S 150 end of script now i'm doing this command : ls -lsgt *REPORT* 4 -rw-r--r-- 300 Sep 16 REPORT54784 4 -rw-r--r-- 301 Sep 16 SREPORT54784 as you can see the sorted file... (5 Replies)
Discussion started by: naamas03
5 Replies

4. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

5. Shell Programming and Scripting

Adding text into file

Hello, I after some assistance please. Below is a file I need to read and for each line write an output. My input file looks like this 2 20008 2003-08-26 2 20032 2003-08-26 2 20041 2003-08-26 2 20037 2003-08-26 2 20050 2003-08-26 6 ... (6 Replies)
Discussion started by: giles.cardew
6 Replies

6. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

7. Shell Programming and Scripting

adding text to a file

Hi All I am making a script in which.I have a problem i try to discribe. File1 content need to be append in file 2 but such as if content already exist then dont add. File1 IS Like this myname yourname hername hisname File2 %AddNameHere myname yourname hername hisname (3 Replies)
Discussion started by: aliahsan81
3 Replies

8. Shell Programming and Scripting

Adding a delimiter to a text file

Im writing a KSH script to read a simple text file and add a delimiter. Ive written the following script but it runs very slow. I initially used the cut command to substring the input record then switched to this version using awk to substring... both run too slow. Any ideas how to make this more... (2 Replies)
Discussion started by: lock
2 Replies

9. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies

10. Shell Programming and Scripting

Adding a character in the beginning of every line in a .dat file

How can i add a character(#) in the beginning of every line in a .dat file (2 Replies)
Discussion started by: Cool Coder
2 Replies
Login or Register to Ask a Question