Sponsored Content
Full Discussion: substring using AWK
Top Forums UNIX for Dummies Questions & Answers substring using AWK Post 302089554 by anbu23 on Tuesday 19th of September 2006 04:47:51 PM
Old 09-19-2006
substr is a function in awk.
You can use following in unix
expr substr "sandeep" 3 3

echo ${"sandeep":3:3} # works in bash
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk substring falls between two values

Hi guys, hopefully you can give me a hand with this before my monitor has a nasty accident! :mad: I have the following line in a script: awk 'int(substr($1,2,2))>'06' && int(substr($1,2,2))<'08' ' ANYOLDFILE.log ... which when ran against this data file: ... correctly... (3 Replies)
Discussion started by: dlam
3 Replies

2. Shell Programming and Scripting

Substring using sed or awk

I am trying to get a substring from a string stored in a variable. I tried sed with a bit help from this forum, but not successful. Here is my problem. My string is: "REPLYFILE=myfile.txt" And I need: myfile.txt (everything after the = symbol). My string is: "myfile.txt.gz.20091120.enc... (5 Replies)
Discussion started by: jamjam10k
5 Replies

3. 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

4. Shell Programming and Scripting

Substring using cut/awk/sed

Hi Gurus,I have a seemingly simple problem but struggling with it.It is as follows : I/p string - ABCDEFGHIJ20100909.txt desired o/p - AB,DEF,20100909,ABCDEFGHIJ20100909.txt How to achieve it ?Thanks in advance. Please use code tags, thank you (20 Replies)
Discussion started by: sumoka
20 Replies

5. Shell Programming and Scripting

KSH: A PROBLEM awk SUBSTRING

Hi Gurus, I am working with a korn shell script to simplify some operations of creation file of spool for a Bulk-Copy. Thi is my code: In a for cycle: gzcat ${file} |awk '{ print substr($0,1,5)";"substr($0,108,122)";"substr($0,124,131)";"substr($0,139,152)";"substr($0,154,163)";"}' >>... (6 Replies)
Discussion started by: GERMANICO
6 Replies

6. Shell Programming and Scripting

awk with multiple regex and substring

Hi Experts, I have a file on which i want to print the line which should match following criterias. Line should not start with 0 or 9 and Line should start with 1 and ( 576th character should not be 1 or 2 or 576-580 postion should not be NIPPF or CDIPB or 576-581 postion should... (2 Replies)
Discussion started by: millan
2 Replies

7. Shell Programming and Scripting

AWK: Substring search

Hi I have a table like this I want to know how many times the string in 2nd column appears in the first column as substring. For example the first string of 2nd column "cgt" occurs 3 times in the 1st column and "acg" one time. So my desired output is THank you very much in advance:) (14 Replies)
Discussion started by: polsum
14 Replies

8. UNIX for Advanced & Expert Users

awk if/substring/append help

Hi All, I need some help with an awk command: What I'm trying to do is append "MYGROUP: " to text with the substring "AT_" the input file follows this format: AT_xxxxxx Name1 Name2 AT_xxxxxx NameA NameB I want the output to be: MYGROUP: AT_xxxxx Name1 Name2 MYGROUP:... (2 Replies)
Discussion started by: bikecraft
2 Replies

9. Shell Programming and Scripting

Extract a substring using SED/AWK

Hi All, I have a log file in which name and version of applications are coming in the following format name It may look like following, based on the name of the application and version: XYZ OR xyz OR XyZ OR xyz I want to separate out the name and version and store them into variables.... (4 Replies)
Discussion started by: bhaskar_m
4 Replies

10. Shell Programming and Scripting

AWK Substring without cutting off word

Can someone help me to make this code without cutting off words ni the string? awk '{for(i=1;i<length;i+=100) print substr($0,i,100)}' Thank you! (4 Replies)
Discussion started by: sanantonio7777
4 Replies
STRRCHR(3)								 1								STRRCHR(3)

strrchr - Find the last occurrence of a character in a string

SYNOPSIS
string strrchr (string $haystack, mixed $needle) DESCRIPTION
This function returns the portion of $haystack which starts at the last occurrence of $needle and goes until the end of $haystack. PARAMETERS
o $haystack - The string to search in o $needle - If $needle contains more than one character, only the first is used. This behavior is different from that of strstr(3). If $needle is not a string, it is converted to an integer and applied as the ordinal value of a character. RETURN VALUES
This function returns the portion of string, or FALSE if $needle is not found. CHANGELOG
+--------+------------------------------------+ |Version | | | | | | | Description | | | | +--------+------------------------------------+ | 4.3.0 | | | | | | | This function is now binary safe. | | | | +--------+------------------------------------+ EXAMPLES
Example #1 strrchr(3) example <?php // get last directory in $PATH $dir = substr(strrchr($PATH, ":"), 1); // get everything after last newline $text = "Line 1 Line 2 Line 3"; $last = substr(strrchr($text, 10), 1 ); ?> NOTES
Note This function is binary-safe. SEE ALSO
strstr(3), strrpos(3). PHP Documentation Group STRRCHR(3)
All times are GMT -4. The time now is 03:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy