awk or sed or paste


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk or sed or paste
# 1  
Old 11-16-2003
awk or sed or paste

i have a file and i need the text to line up
currently the file looks like so


job scheduled complete
12 12:00 wendsday
13 1:00 wednsday

its a text file but not sure how to manipulate the file for it to line up
# 2  
Old 11-16-2003
For example:

$ cat ick4 | awk '{printf("%5s %10s %10s\n", $1,$2,$3)}'

You can change the justification with - for example:

$ cat ick4 | awk '{printf("%-5s %-10s %-10s\n", $1,$2,$3)}'

Cheers,
Keith

Last edited by kduffin; 11-17-2003 at 10:37 PM..
# 3  
Old 11-16-2003
thankyou that helped alot would you mind explaining that command a little bit i almost understand it all
but i am very new to unixand nice web page in the making
# 4  
Old 11-16-2003
The cat command reads the file passed to it and outputs it to standard out. However, in this case, its is "piped" to the command awk. By piped I mean, the output of the command cat is passed as input to the command awk.

The awk programming language uses regular expressions and pattern matching. Its a great tool for parsing text files and the like. The printf statement has the general form:

printf format, expr[1], expr[2], . . ., expr[n]

where format is a string that contains both information to be printed and specifications on what conversions are to be performed on the expressions in the argument list, as in ``awk printf conversion characters''. Each specification begins with a %, ends with a letter that determines the conversion, and may include:
- (the dash) is used to Left-justify an expression in its field.
Character Prints expression as
c single character
d decimal number
e [-]d.ddddddE[+-]dd
f [-]ddd.dddddd
g e or f conversion, whichever is shorter, with nonsignificant zeros suppressed
o unsigned octal number
s string
x unsigned hexadecimal number
% print a %; no argument is converted


Below are some examples of printf statements along with the corresponding output:

printf "%d", 99/2 49
printf "%e", 99/2 4.950000e+01
printf "%f", 99/2 49.500000
printf "%6.2f", 99/2 49.50
printf "%g", 99/2 49.5
printf "%o", 99 143
printf "%06o", 99 000143
printf "%x", 99 63
printf "|%s|", "January" |January|
printf "|%10s|", "January" | January|
printf "|%-10s|", "January" |January |
printf "|%.3s|", "January" |Jan|
printf "|%10.3s|", "January" | Jan|
printf "|%-10.3s|", "January" |Jan |
printf "%%" %

The default output format of numbers is %.6g; this can be changed by assigning a new value to OFMT. OFMT also controls the conversion of numeric values to strings for concatenation and creation of array subscripts.

Last edited by google; 11-16-2003 at 10:24 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use sed/awk to do like copy and paste

I have rrd file which is have the gaps and I want to fill it out with some value , I've got 10 NaN record and I try to populate data from 10 records be for NaN to change instead of NaN :( <!-- 2016-05-19 14:10:00 CST / 1463638200 -->... (11 Replies)
Discussion started by: boobytrap
11 Replies

2. Shell Programming and Scripting

Using SED to copy/paste with slashes and tabs.

I have: 2012/01_January/Kite/foldername/otherfoldername/placeholderBlue I want to end up with: /foldername/otherfoldername/2012/01_January/Kite/Blue Basically take everything before the first tab and put it in the place of the consistently named word placeholder and add a slash in place... (2 Replies)
Discussion started by: crowman
2 Replies

3. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

4. Shell Programming and Scripting

sed copy paste

Hello, I have this path and file: /dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txt I want to end up with: /dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txtTHIS_SPOT Take the dir after the 10th slash, add a tab at the end and paste the dir it copied. Thanks (4 Replies)
Discussion started by: crowman
4 Replies

5. Shell Programming and Scripting

Paste value at specific column using sed

Hi I want to paste some value at specific column in a file using sed. say I want to add "Welcome to UNIX" from column 300 onwards in a file using sed. How to do it . ---------- Post updated at 11:18 AM ---------- Previous update was at 11:09 AM ---------- Adding more information : I... (14 Replies)
Discussion started by: dashing201
14 Replies

6. Shell Programming and Scripting

copy/paste with awk

Hi everybody, I have two XML files. I am working on a script that could copy and paste the contents of the first xml file to the desired location in the second xml file. Here is my first XML file. This is the second XML file. Finaly, I wnat to obtain something like that : ... (2 Replies)
Discussion started by: lsaas
2 Replies

7. Shell Programming and Scripting

cut and paste using awk

Hi i need a favour i have a file which has some trillions of records. The file is like this 11111000000000192831840914000000000000000000000000000 45789899090000000000000000011111111111111111111111111 I want to cut specific postions in each line like cut1-3 and assisgn it to a variable and... (5 Replies)
Discussion started by: richa2.m
5 Replies

8. Shell Programming and Scripting

appending several columns with awk and paste

Hello, I am trying to solve for a couple of hours now the following problem: I have n files and would like to add the third column of each file to a new file: temp1.txt 1 2 3 1 2 3 1 2 3 temp2.txt 1 2 4 1 2 4 1 2 4 1 2 4 temp3.txt (2 Replies)
Discussion started by: creamcheese
2 Replies

9. Shell Programming and Scripting

awk with paste ... columnwise

Hi, I'm trying to plot some data using the awk to find and parse the data and then use gnuplot to plot it up. I'd like to plot one or more range cells (let the user decide!). I've been able to write up the code such that I can plot one range cell per plot, but I just can't see how to get more... (1 Reply)
Discussion started by: dpath2o
1 Replies

10. Shell Programming and Scripting

how to replace paste utility with sed/awk

hi I have two file that I would like to paste line by line. I use to use paste for this. But my current platform will not have paste utility. Could anyone please suggest how I it can be done using sed,awk or even simple bourne shell scripts? Thanks Sabina (1 Reply)
Discussion started by: ssayeed
1 Replies
Login or Register to Ask a Question