Character printing with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Character printing with AWK
# 1  
Old 10-27-2012
Character printing with AWK

I was wondering if I could use AWK to print from the nth character position to nth for all records in the file.

All I have been doing is printing/copying fields rather than characters. I found a way to print lines greater/less/equal to a character length which led me to believe there is a way to do this in awk.

If this can't be done in awk, then how could it be done?

Thanks!
# 2  
Old 10-27-2012
There is the substr function in AWK, but to be honest your question is slightly vague.

Can you elaborate by showing a sample input and desired output? (using code tags, please Smilie)
# 3  
Old 10-27-2012
You can use awk with substr funtion.

Syntax:-

Code:
awk ' { print substr(string, start, length) } '

This User Gave Thanks to Yoda For This Post:
# 4  
Old 10-27-2012
Quote:
Originally Posted by Scott
There is the substr function in AWK, but to be honest your question is slightly vague.

Can you elaborate by showing a sample input and desired output? (using code tags, please Smilie)
Scott,

I have been doing this:

Code:
awk '{printf $0; for (i=1;i<=19;i++) printf $4; printf "\n"}' file

This was to print over the 4th field 19 more times, now due to the fact that some records in the file only had 3 fields, it wasn't the best option. I wanted to go with printing lets say from character position 25 to 40 for all lines in the file, as that would be the best option to copy over what I actually need.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

printing only columns containing a determined character with awk

Hello I'm trying to extract two columns from a database using awk, the thing is i have a variable number of columns in each row, and I just need to get out the two first ones ending in "," This is an example: ABE, ABE V149 MAZIE ARD CYN ACY, ACY, , , ,TEC, , 5000, , , 1, ZNY,ZDC ABE, ABE... (1 Reply)
Discussion started by: vir
1 Replies

2. Shell Programming and Scripting

Printing using awk

Hi I am relatively new to awk so i am getting confused a lot I am in need of help ... I am trying to append coloumns to the end of line using AWK I tried using this command awk -F "," '{for(s=7;s<=217;s++);$s="0";}1' OFS=, sam_sri_out It is giving me an output like this...... (1 Reply)
Discussion started by: Sri3001
1 Replies

3. Shell Programming and Scripting

Awk while-loop printing extra character

Hi, I'm using a while-loop in an awk script. If it matches a regular expression, it prints a line. Unfortunately, each line that is printed in this loop is followed by an extra character, "1". While-statement extracted from my script: getline temp; while (temp ~ /.* x .*/) print temp... (3 Replies)
Discussion started by: redbluefish
3 Replies

4. Shell Programming and Scripting

How to use a subscript and a super script while printing a character

I want to print a output after executing a awk command How to represent a subscript or a superscript while using print command eg : Ts. where character 's' is subscript of T T2 where '2' is the superscript of T thank you. Shashi: (3 Replies)
Discussion started by: shashi792
3 Replies

5. Shell Programming and Scripting

Awk printing help

Hallo, i have a file which looks like this: $1 $2 $3 Student1 55 Pass 55 Pass 35 Fail Student2 55 Pass 55 Pass 35 Fail i want that the $1 field... (3 Replies)
Discussion started by: saint2006
3 Replies

6. Shell Programming and Scripting

Printing special character in bash

I am using this character as a delimiter 'þ' Currently, I set it straight: DELIMITER='þ' However, while copying the file, this character often gets mangled. Is there a bash way (perhaps using tr or printf) of generating this character. It corresponds to "chr(0xfe)" if using perl. (I've... (6 Replies)
Discussion started by: sentinel
6 Replies

7. Shell Programming and Scripting

AWK printing

i have a file containing a line 123456 is it possible to use AWK to print it out to look like 1 2 3 4 5 6 (8 Replies)
Discussion started by: tomjones
8 Replies

8. Shell Programming and Scripting

AWK Printing

i have a file and i want to print the second variable and add qoutes to it i do awk -F"|" '{print $2}' star.unl. i get the output xxxxxxx but i need the variable($2) to be in quotes.like "xxxxxxx" how do i do there please (3 Replies)
Discussion started by: tomjones
3 Replies

9. UNIX for Dummies Questions & Answers

[OpenServer 5]Line Printing and special character (é @)

Hello, On Sco OpenServer 5, i want to print using the lpr command, no CUPS installed. I print on an HP LaserJet 4050 on LAN (IP 192.168.x.x) the printer is installed by HP Network Printer service. it works fine, but Specials characters, like é, @ or ° print bad characters. Is there... (5 Replies)
Discussion started by: tankd
5 Replies

10. Shell Programming and Scripting

AWK printing

Hello, I am trying to write a formatted report into a file using .ksh script and awk. Here is the command I am trying to run echo "before awk" ${SRC_SCHEMA} echo | awk '{printf "%-20s", ${SRC_SCHEMA} }' >>$REPORT_SQL_NAME I get the following error before awk ADW awk: 0602-562 Field $()... (1 Reply)
Discussion started by: fastgoon
1 Replies
Login or Register to Ask a Question