AWK Substring without cutting off word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Substring without cutting off word
# 1  
Old 07-24-2012
AWK Substring without cutting off word

Can someone help me to make this code without cutting off words ni the string?

Code:
awk '{for(i=1;i<length;i+=100) print substr($0,i,100)}'


Thank you!
# 2  
Old 07-24-2012
An alternative:
Code:
awk '{gsub(/.{100}/,"&^");n=split($0,a,"^");for(i=1;i<=n;i++) print a[i]}' inputfile

Assuming that "^" character does not appear in the input records.
This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 07-24-2012
Quote:
Originally Posted by elixir_sinari
An alternative:
Code:
awk '{gsub(/.{100}/,"&^");n=split($0,a,"^");for(i=1;i<=n;i++) print a[i]}' inputfile

Assuming that "^" character does not appear in the input records.
48.being used as a therapy,” she says. resting thro
50.ugh although far-fetched, that in the future we co
48.uld think of cancer being used as a therapy,” sh
50.e says. treatment, Jayant believed that her mind a
49.nd spirit needed healing in addition to her body.

still cut the words... any other ideas why ?
thank you! Smilie
# 4  
Old 07-24-2012
If that's what you want, why not use the fold command? fold -w 100 -s
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 07-24-2012
wow this is great command!!!
Thank you!!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. UNIX for Beginners Questions & Answers

Finding a word through substring in a file

I have a text file that has some data like: PADHOGOA1 IOP055_VINREG5_1 ( .IO(VINREG5_1), .MONI(), .MON_D(px_IOP055_VINREG5_1_MON_D), .R0T(px_IOP054_VINREG5_0_R0T), .IO1() ); PADV30MA0 IOP056_VOUT3_IN ( .IO(VOUT3_IN), .V30M(px_IOP056_VOUT3_IN_V30M)); PADV30MA0 IOP057_VOUT3_OUT (... (2 Replies)
Discussion started by: utkarshkhanna44
2 Replies

3. Shell Programming and Scripting

Bash - Extracting whole word containing substring

hello. I get this text when using some command : S | Name | Type | Version | Arch | Repository --+-----------------+---------+---------+------+------------- | AdobeReader_enu | package | 9.5.4-1 | i486 | zypper_local I need to get "AdobeReader_enu" from the the pattern "Ado"... (7 Replies)
Discussion started by: jcdole
7 Replies

4. Shell Programming and Scripting

Perl Cutting character(s) from a word

Hello, How to cut a char(s) for a word using perl?? I want to cut the number(s) from these sample words: Port-channel24 Po78 Po99 Port-channel34 $word = "Port-channel24"; I want to put only the number in a varible. Appreaciate using simple way in order to use it... (3 Replies)
Discussion started by: ahmed_zaher
3 Replies

5. Shell Programming and Scripting

Getting substring with awk

Hi Team, How to get the last 3 characters of a String irrespective of their length using awk? Thanks Kinny (5 Replies)
Discussion started by: kinny
5 Replies

6. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

7. Shell Programming and Scripting

Need Help in Cutting a word

Hi All , i am working on a backup script , which would a call a executable file in unix server , Login credentials :: use telnet session to login to Unix server when logged in, this would be my Prompt ::: unix11@raghav: I just need to cut the word unix11 , so that i can use this... (12 Replies)
Discussion started by: raghav1982
12 Replies

8. Shell Programming and Scripting

cutting fields and doing trim in awk

hi, I have this code: #!/usr/bin/ksh #SERVICES gzcat *SERVICES* | awk ' { SUBSCRIBERNUMBER=substr($0,1,20) SUBSCRIBERNUMBER=trim(SUBSCRIBERNUMBER) SERVICECODE=substr($0,22,61) SERVICECODE=trim(SERVICECODE) STARTDD=substr($0,63,72) STARTDD=trim(STARTDD) STARTDT=substr($0,74,81)... (1 Reply)
Discussion started by: naoseionome
1 Replies

9. Shell Programming and Scripting

need help cutting consecutive lines with sed or awk

HI All, I want to cut 5 lines after a pattern using sed or awk. can any one tell me how to do it ? (2 Replies)
Discussion started by: raghin
2 Replies

10. UNIX for Dummies Questions & Answers

substring using AWK

can we do substring fuctionality using AWK say I have string "sandeep" can i pick up only portion "nde" from it. Thanks and Regards Sandeep Ranade (3 Replies)
Discussion started by: mahabunta
3 Replies
Login or Register to Ask a Question