Sponsored Content
Top Forums Shell Programming and Scripting Selecting a part of the text (regex pattern, awk, sed) Post 302455494 by rdcwayx on Tuesday 21st of September 2010 09:00:44 PM
Old 09-21-2010
-F" " is useless, because it is default FS

And you need tell use your expect O/P

for example, for this string: /TEXT123/TEXT456/ABC123/

what will be TEXT and ABC?

Seems basename and dirname will help you.

---------- Post updated at 11:00 AM ---------- Previous update was at 10:55 AM ----------

Code:
cat infile |while read LINE; 
do  
  TEXT=$( echo $LINE|awk '{gsub(/"/,"");print $2}' |xargs dirname)
  ABC=$(echo $LINE|awk '{gsub(/"/,"");print $2}' |xargs basename)
done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Selecting line ahead and next using AWK or SED

:confused: Good Day, I have this script that gets the archive names and the time it applies based on the alert log. The application of archives are of daily basis and usually many so having this script helps my job become easier. My problem is that when i get all the time stamps and... (1 Reply)
Discussion started by: ownins
1 Replies

2. Shell Programming and Scripting

RegEx for text pattern

Hi, Please help me write regex for text pattern like CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3, ...so on Any advice is Okay! Thanks in advance. (6 Replies)
Discussion started by: rider29
6 Replies

3. Shell Programming and Scripting

sed to awk (regex pattern) how?

Hello, I am trying to covert a for statement into a single awk script and I've got everything but one part. I also need to execute an external script when "not found", how can I do that ? for TXT in `find debugme -name "*.txt"` ;do FPATH=`echo $TXT | sed 's/\(.*\)\/\(.*\)/\1/'` how... (7 Replies)
Discussion started by: TehOne
7 Replies

4. UNIX for Dummies Questions & Answers

blank space in regex pattern using sed

why does sed 's/.* //' show the last word in a line and sed 's/ .*//' show the first word in a line? How is that blank space before or after the ".*" being interpreted in the regex? i would think the first example would delete the first word and the next example would delete the second... (1 Reply)
Discussion started by: glev2005
1 Replies

5. Shell Programming and Scripting

Using Sed to remove part of line with regex

Greetings everyone. Right now I am working on a script to be used during automated deployment of servers. What I have to do is remove localhost.localdomain and localhost6.localdomain6 from the /etc/hosts file. Simple, right? Except most of the examples I've found using sed want to delete the entire... (4 Replies)
Discussion started by: msarro
4 Replies

6. Shell Programming and Scripting

Selecting specific 'id's from lines and columns using 'SED' or 'AWK'

Hello experts, I am new to this group and to 'SED' and 'AWK'. I have data (text file) with 5 columns (C_1-5) and 100s of lines (only 10 lines are shown below as an example). I have to find or select only the id numbers (C-1) of specific lines with '90' in the same line (of C_3) AND with '20' in... (6 Replies)
Discussion started by: kamskamu
6 Replies

7. Shell Programming and Scripting

Replacing part of a pattern in sed

Hi I have a piece of xml that has a pattern like this <int>159</int><int>30</int> I want to find this pattern but only substitute the second part of the pattern to {rid1}. Is that possible in sed ? Thanks. ---------- Post updated at 12:10 PM ---------- Previous update was at 12:01 PM... (11 Replies)
Discussion started by: vnn
11 Replies

8. Shell Programming and Scripting

SED: Pattern repitition regex matching

Fairly straightforward, but I'm having an awful time getting what I thought was a simple regex to work. I'll give the command I was playing with, and I'm aware why this one doesn't work (the 1,3 is off the A-Z, not the whole expression), I just don't know what the fix is: Actual Output(s): $... (5 Replies)
Discussion started by: Vryali
5 Replies

9. Shell Programming and Scripting

Regex in sed to find specific pattern and assign to variable

(5 Replies)
Discussion started by: radioactive9
5 Replies

10. UNIX for Advanced & Expert Users

sed REGEX to print multiple occurrences of a pattern from a line

I have a line that I need to parse through and extract a pattern that occurs multiple times in it. Example line: getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed,... (4 Replies)
Discussion started by: Vidhyaprakash
4 Replies
BASENAME(3)								 1							       BASENAME(3)

basename - Returns trailing name component of path

SYNOPSIS
string basename (string $path, [string $suffix]) DESCRIPTION
Given a string containing the path to a file or directory, this function will return the trailing name component. PARAMETERS
o $path - A path. On Windows, both slash ( /) and backslash ( ) are used as directory separator character. In other environments, it is the forward slash ( /). o $suffix - If the name component ends in $suffix this will also be cut off. RETURN VALUES
Returns the base name of the given $path. EXAMPLES
Example #1 basename(3) example <?php echo "1) ".basename("/etc/sudoers.d", ".d").PHP_EOL; echo "2) ".basename("/etc/sudoers.d").PHP_EOL; echo "3) ".basename("/etc/passwd").PHP_EOL; echo "4) ".basename("/etc/").PHP_EOL; echo "5) ".basename(".").PHP_EOL; echo "6) ".basename("/"); ?> The above example will output: 1) sudoers 2) sudoers.d 3) passwd 4) etc 5) . 6) NOTES
Note basename(3) operates naively on the input string, and is not aware of the actual filesystem, or path components such as " ..". Note basename(3) is locale aware, so for it to see the correct basename with multibyte character paths, the matching locale must be set using the setlocale(3) function. SEE ALSO
dirname(3), pathinfo(3). PHP Documentation Group BASENAME(3)
All times are GMT -4. The time now is 03:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy