Help with Fixed with data


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with Fixed with data
# 8  
Old 03-12-2012
Thanks a lot guys

---------- Post updated at 12:44 PM ---------- Previous update was at 08:57 AM ----------

ANd one more doubt guys y is that we have 1 after every completeion awk command andf before the inputfile
# 9  
Old 03-12-2012
That '1' at the end refers to print line.

See these examples to get a clearer picture:

Code:
$ cat input
earth
hello
world
mars
$
$ ### If line contains "hello", replace "ll" with "LL" and print all lines
$ awk '/hello/ {sub(/ll/, "LL", $0)}{print}' input
earth
heLLo
world
mars
$
$ ### Same thing with 1 at the end
$  awk '/hello/ {sub(/ll/, "LL", $0)}'1 input
earth
heLLo
world
mars
$
$ ### If line contains "hello", replace "ll" with "LL" and print only that line. (Observe where print is placed here)
$ awk '/hello/ {sub(/ll/, "LL", $0); print}' input
heLLo

This User Gave Thanks to balajesuri For This Post:
# 10  
Old 03-13-2012
With "doubt" you mean "question", right? Bala could have put the 1 inside the single quotes, which is usually done, it does not matter. Everything in awk has the form condition{action}. If the condition evaluates to 1 then the action is performed. If the condition is omitted then the action is always performed. If the action is omitted then the default action in awk is performed, which is {print $0}. In this case the condition is "1" so that evaluates to 1 and the action is omitted, therefore {print $0} is performed, which is print the entire record.

@balajesuri, #2 will print matching lines twice on the same line...

Last edited by Scrutinizer; 03-13-2012 at 02:08 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 11  
Old 03-13-2012
Quote:
Originally Posted by Scrutinizer
@balajesuri, #2 will print matching lines twice on the same line...
Is it this one??
Code:
awk '/hello/ {sub(/ll/, "LL", $0)}'1 input

# 12  
Old 03-13-2012
Quote:
Originally Posted by balajesuri
Is it this one??
Code:
awk '/hello/ {sub(/ll/, "LL", $0)}'1 input

No I mean this one:
Quote:
Originally Posted by balajesuri
Something like this?

Code:
awk '/^500/ {printf "%-100s", $0}'1 inputfile

# 13  
Old 03-13-2012
Ah yes, you're right. Didn't notice that. Silly typo Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk issue splitting a fixed-width file containing line feed in data

Hi Forum. I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type. The main command in the script is: awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Discussion started by: pchang
8 Replies

2. Post Here to Contact Site Administrators and Moderators

How to sum up data in fixed width file with decimal point?

HI Everyone, I have below source file AAA|NAME1|ADDRESS1|300.20 BBB|NAME2|ADDRESS2|400.31 CCC|NAME3|ADDRESS3|300.34 I have requirement where I need to sum up fourth field in above fixed width pipe delimited flat file. When I use below code, it gives me value 1001.00 But I am expecting... (1 Reply)
Discussion started by: patricjemmy6
1 Replies

3. Shell Programming and Scripting

Ignore Header and Footer and Sort the data in fixed width file

Hi Experts, I want to Sort the data in fixed width file where i have Header and Footer also in file. I m using below commad to do the sort based on field satarting from 15 position to 17 position , but it is not ignoring the Header and Footer of the file while sorting. In the output i am... (5 Replies)
Discussion started by: sasikari
5 Replies

4. Shell Programming and Scripting

Fixed length fields

HPUX and posix shell Hi all. I have a record with fixed length fields....I would like to reorder the fields and preserver the fixed lengths.... cat test 4 960025460 Dept of Music 8 960025248 Dept of Music 12-08 cat... (3 Replies)
Discussion started by: lyoncc
3 Replies

5. Shell Programming and Scripting

Getting a string without fixed delimiters

I have a line of text for example aaaa bbbb cccc dddd eeee ffffff I would need to get the cccc however bbbb could be there or not. So whether bbbb is in the line or not I need cccc. I was looking at either awk or sed....and trying to start at c and end until the next space. Also... (11 Replies)
Discussion started by: bombcan1
11 Replies

6. Shell Programming and Scripting

Script need to get fixed

I need immediate help with this code. I do want to through the output of query into the log file and then on behelf of result i do want to automate an email warning system. while compiling this code i failed to through the output into the log file. To avoid manual password change for... (3 Replies)
Discussion started by: asifrafiqe
3 Replies

7. Shell Programming and Scripting

row to column and position data in to fixed column width

Dear friends, Below is my program and current output. I wish to have 3 or 4 column output in order to accomodate in single page. i do have subsequent command to process after user enter the number. Program COUNT=1 for MYDIR in `ls /` do VOBS=${MYDIR} echo "${COUNT}. ${MYDIR}" ... (4 Replies)
Discussion started by: baluchen
4 Replies

8. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

9. Shell Programming and Scripting

Fixed Format File

Hi to All, Would you please help me. I have a issue like in fixed format file there are 80 words should be there. but if file contains greater than 80 words then creates problem. so i have to trim file having more than 80 characters line through unix shell scripting. Please let me know how... (2 Replies)
Discussion started by: div_Neev
2 Replies
Login or Register to Ask a Question