Sponsored Content
Top Forums Shell Programming and Scripting how to know if a string contains a certain pattern Post 302130856 by firdousamir on Wednesday 8th of August 2007 05:00:30 AM
Old 08-08-2007
echo $string1 | grep -c $string2
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to get the last part of a string followed by a pattern

assuming "cat" is the pattern, string (regardless length) asdadfcat4 I need to get 4 for eirtrjkkkcat678- I'd get 678 (in b-shell) Thanks in advance!!! (4 Replies)
Discussion started by: bluemoon1
4 Replies

2. Shell Programming and Scripting

Compare string to a pattern

I am new to unix and need to learn how to compare a variable $subject to a string pattern. If the variable has the word "Item" in it then it should be true. How do I do this? Currently I am using the Bourne shell but I can also use Korn or Bash. I come from a Rexx background where strings are... (2 Replies)
Discussion started by: jerryte
2 Replies

3. UNIX for Dummies Questions & Answers

How to search for a pattern a string?

Hi all, I'm new in UNIX , so how to check if stringA is present within stringB ? Something similar to INSTR function in pl sql... Thanks a lot. (12 Replies)
Discussion started by: Leo_NN
12 Replies

4. Shell Programming and Scripting

Looking for pattern next to variable string

Hi, I need to help to find the way to get specific data from a log, an unknow string beside a string that is the same always, for example: Input file: ctmdefine -TASKTYPE COMMAND -TABLE PRUEBAS_BIMLAR -JOBNAME PRUEBAJOB12 \ -GROUP PRUEBAS_BIM2 -APPLICATION PRUEBAS_BIM2 -NODEGRP gtwtran... (4 Replies)
Discussion started by: mgcorona
4 Replies

5. Shell Programming and Scripting

extract a string within a string using a pattern

hi all, i have a file name using the following pattern: PREFIX: AR SOURCE: LEGACY DATETIME: YYYYMMDD_HH24MISS SUFFIX: .txt sample filename: AR_LEGACY_20101104_105500.txt i want to extract the source which is LEGACY in this case. how do i do this using shell? thanks. (4 Replies)
Discussion started by: adshocker
4 Replies

6. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
4 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

9. Shell Programming and Scripting

Replace a string pattern

Hi, I have a CSV with following type of data and would like to replace the timestamp information with 'null' string. Can you please suggest me on same? 8,1,'1','1',11,'2013-08-12 18:34:17.0','null',1,'2013-08-12 18:34:17.0','null','PROMOTIONAL','12','1','11','11',11,'0' Thanks for your... (10 Replies)
Discussion started by: bhupinder08
10 Replies

10. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies
TR(1)							      General Commands Manual							     TR(1)

NAME
tr - translate characters SYNOPSIS
tr [ -cds ] [ string1 [ string2 ] ] DESCRIPTION
Tr copies the standard input to the standard output with substitution or deletion of selected characters. Input characters found in string1 are mapped into the corresponding characters of string2. When string2 is short it is padded to the length of string1 by duplicat- ing its last character. Any combination of the options -cds may be used: -c complements the set of characters in string1 with respect to the universe of characters whose ASCII codes are 01 through 0377 octal; -d deletes all input characters in string1; -s squeezes all strings of repeated output characters that are in string2 to single characters. In either string the notation a-b means a range of characters from a to b in increasing ASCII order. The character `' followed by 1, 2 or 3 octal digits stands for the character whose ASCII code is given by those digits. A `' followed by any other character stands for that character. The following example creates a list of all the words in `file1' one per line in `file2', where a word is taken to be a maximal string of alphabetics. The second string is quoted to protect `' from the Shell. 012 is the ASCII code for newline. tr -cs A-Za-z '12' <file1 >file2 SEE ALSO
ed(1), ascii(7) BUGS
Won't handle ASCII NUL in string1 or string2; always deletes NUL from input. TR(1)
All times are GMT -4. The time now is 12:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy