Visit Our UNIX and Linux User Community

Use awk to print first 6 characters

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use awk to print first 6 characters
# 1  
Old 09-06-2010
Use awk to print first 6 characters

i want to use awk to print the first 6 characters of a variable

awk -F"|" '$3>0 { print $3 }' z00.unl > z001.unl

but $3= 7 digits
and i just want to print the first 6 digits.

eg 1005779 but i want to print only 100577

Last edited by Scott; 09-06-2010 at 08:10 AM.. Reason: Please use code tags
# 2  
Old 09-06-2010
$ cat file1

$ awk -F\| '$3 > 0 { print substr($3,1,6)}' file1

This User Gave Thanks to Scott For This Post:
# 3  
Old 09-06-2010
awk -F"|" '$3>0 { print substr($3,1,6)}'

This User Gave Thanks to pravin27 For This Post:
# 4  
Old 09-06-2010
thanks the awk worked

Previous Thread | Next Thread
Test Your Knowledge in Computers #999
Difficulty: Easy
The trusted computing base (TCB) of a computer system is the set of all hardware, firmware, and/or software components that are critical to its security.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print column number while ignoring alpha characters

I have the following script that will print column 4 ("25") when column 1 contains "123". However, I need to ignore the alpha characters that are contained in the input file. If I were to ignore the characters my output would be column 3. What is the best way to print my column of interest... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

2. Shell Programming and Scripting

How to ignore characters and print only numbers using awk?

Input: ak=70&cat15481=lot=6991901">Kaschau (1820-1840) ak=7078&cat15482=lot=70121">Principauté (1940-1993) ak=709&cat=lot15484=70183944">Arubas (4543-5043)Output: 70 15481 6991901 7078 15482 70121 709 15484 70183944 (11 Replies)
Discussion started by: sdf
11 Replies

3. Shell Programming and Scripting

How to print the first 7 characters of each column

Hello all, I have a data like this: X:04252 X:05524 X:04176 X:05509 X:05524 X:04674- X:1662912 X:10181 X:16491 X:05506 X:05216- X:05488 X:46872 X:08471 X:04834 X:30170 The except result is like this: X:04252 X:05524 X:04176 X:05509 X:05524 X:04674 X:16629 X:10181... (3 Replies)
Discussion started by: yhkoo
3 Replies

4. Shell Programming and Scripting

Print N characters in ksh

Hi, I have this header on a script: echo "*************************************" How can I print 1000 "*" characters without to put them on the echo command? Understand? THIS IS AN EXAMPLE WHAT I NEED: print "1000 *" Or is possible to print or echo "*" characters until they... (8 Replies)
Discussion started by: iga3725
8 Replies

5. Shell Programming and Scripting

awk print $1 escape all special characters

I'm using awk '{print $1}' and it works most of the time to print the contents of a mysql query loop, but occationally I get a field with some special character in it, is there a way to tell awk to ignore all special characters between my FS? I have >186K records, so building a list of ALL special... (6 Replies)
Discussion started by: unclecameron
6 Replies

6. Shell Programming and Scripting

Awk , Sed Print last 4 numeric characters

Hello All, I have been searching and trying this for a bit now. Can use some assistance. Large 5000 line flat file. bash, rhel5 Input File Sinppet: Fri Oct 30 09:24:02 EDT 2009 -- 1030 Fri Oct 30 09:26:01 EDT 2009 -- 73 Fri Oct 30 09:28:01 EDT 2009 -- 1220 Fri Oct 30 09:30:01 EDT... (9 Replies)
Discussion started by: abacus
9 Replies

7. Shell Programming and Scripting

Print the first four characters of hostname

Hey, I'm trying to print the first four characters of the hostname of a computer. I can get it from using: hostname -s | sed 's/...........$//'" but this is when I know how many characters are in the computer name. I dont understand why some like: hostname -s | sed '/..../p' wont... (7 Replies)
Discussion started by: yxian
7 Replies

8. Shell Programming and Scripting

print 10 characters in series

suppose fileA kanika123ABC 1222222222222222 raciat5678ty 1221123333331121 jessica78ulllo 2233243223333333 so output shud be print only first 10 characters in series and rest remain same kanika123A 1222222222222222 raciat5678 1221123333331121 jessica78u ... (1 Reply)
Discussion started by: cdfd123
1 Replies

9. Shell Programming and Scripting

Print the characters in a word

Hi, How can I split the characters in a word? For Eg: If my input is: command my output should be: c o m m a n d Please help me in doing it so. (5 Replies)
Discussion started by: chella
5 Replies

10. AIX

AIX cannot print thai characters

Anyone has experience on this? The additional language has been smitty added and enabled. But it still prints garbage. What else needs to be done? Printer is a HP laserjet 4350. (0 Replies)
Discussion started by: ivanwee
0 Replies

Featured Tech Videos