Sponsored Content
Full Discussion: matching a string
Top Forums Shell Programming and Scripting matching a string Post 302310428 by durden_tyler on Friday 24th of April 2009 06:28:28 PM
Old 04-24-2009
Quote:
Originally Posted by dsdev_123
I have a requirement of shell script where i need to read the File name i.e ls -t | head -1
Code:
$
$ # For simplicity, assume that the files to loop through are the ones that have 4 characters
$
$ ls -1 ????
aaaa
kkkk
nnnn
xxxx
$

Quote:
and Match that Filename with some delimited values which are in a separate File.

For Example i am reading the File name i.e (ls -t | head -1) after that i need to read one more sequential file which contains some delimited values like this

00000%/aaa/bbb/ccc%kkkk%/ddd/eee/kkkk/fff^%^12345%/ggg/hhh/iii%nnnn%/jjj/kkk/lll/nnnn^%^

The record delimiter string is ^%^
Code:
$
$ # Assume that the sequential file is list.txt
$
$ cat list.txt
00000%/aaa/bbb/ccc%kkkk%/ddd/eee/kkkk/fff^%^12345%/ggg/hhh/iii%nnnn%/jjj/kkk/lll/nnnn^%^
$

Quote:
So If my file name matches kkkk then i need to match with the above list and i need to get /ddd/eee/kkkk/fff if my file name is nnnn then i need to get /jjj/kkk/lll/nnnn .
Code:
$
$ # something like this could be done
$
$ for i in ???? ; do echo "File = $i"; sed 's/\^%\^/\n/g' list.txt | grep "%$i%" | sed 's/^.*%//'; done
File = aaaa
File = kkkk
/ddd/eee/kkkk/fff
File = nnnn
/jjj/kkk/lll/nnnn
File = xxxx
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

matching alphanumeric string

how to match an alphanumeric string like the following. i have to do like the following. if the input line is the data is {clock_91b} i have to replace that with the string was ("clock_91b") i tried like $line =~ s/the data is\s+\{(+)\}/the string was \(\"$1\"\)/ which... (4 Replies)
Discussion started by: sskb
4 Replies

2. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

3. Shell Programming and Scripting

String matching

for a certain directory, I want to grep a particular file called ABCD so what I do is ls /my/dir | grep -i "ABCD" | awk '{print $9}' however, there is also this file called ABCDEFG, the above command would reurn both file when I only want ABCD, please help! (3 Replies)
Discussion started by: mpang_
3 Replies

4. Shell Programming and Scripting

string matching in perl

Hi, I have to search for a string in a variable. Say the variable is var1='ERROR: Make java] as enabled' here i want to match which are in red color. other like abc etc could change. Can you tell me the exact command something like the below in perl if ($var1=~ m/ERROR: Make... (3 Replies)
Discussion started by: ammu
3 Replies

5. UNIX for Dummies Questions & Answers

Matching string

Hello, i have a program where i have to get a character from the user and check it against the word i have and then replace the character in a blank at the same position it is in the word. (7 Replies)
Discussion started by: nehaquick
7 Replies

6. Shell Programming and Scripting

Matching 2 items in a string

Little lost here, I am trying to search a line for both values after the $ signs. My ultimate goal is to get percertage. <?php $string = "Something on sale for $4 and orginal price $10"; $strstr =. strstr($string, '$'); $strrchr =. strrchr($string, '$'); echo "$strstr<br>"; echo... (1 Reply)
Discussion started by: mrlayance
1 Replies

7. Shell Programming and Scripting

String matching

I have a string like ab or abc of whatever length. But i want to know whether another string ( for example, abcfghijkl, OR a<space> bcfghijkl ab<space> cfghijkl OR a<space>bcfghijkl OR ab<space> c<space> fghijkl ) starts with ab or abc... space might existing on the longer string... If so, i... (4 Replies)
Discussion started by: nram_krishna@ya
4 Replies

8. Shell Programming and Scripting

Matching string from input to string of file

Hi, i want to know how to compare string of file with input string im trying following code: file_no=`paste -s -d "||||\n" a.txt | cut -c 1` #it will return collection number from file echo "enter number" read " curr_no" if ; then echo " current number already present" fi ... (4 Replies)
Discussion started by: a_smith
4 Replies

9. Shell Programming and Scripting

String matching using awk

Hello, I am working with google ngram data set which is of size 100s of gb. Before using it with Java, I wanted to filter it out using shell script. Here is a sample line in the file: 2.55 1.57 1992 10 20 30 The first two fields (2.55 and 1.57) are... (3 Replies)
Discussion started by: shekhar2010us
3 Replies

10. UNIX for Dummies Questions & Answers

Matching string

Hello all, i am trying to match a string and based on that proceed with my script or error out... i have a file called /tmp/sta.log that will be populated by oracle's spooling..it can have a output of either 2 of the below (OPEN or errors/ORACLE not avaiable) $ cat /tmp/sta.log OPEN $ $... (2 Replies)
Discussion started by: abdul.irfan2
2 Replies
srec_ti_tagged(5)						File Formats Manual						 srec_ti_tagged(5)

NAME
srec_ti_tagged - Texas Instruments Tagged (SDSMAC) file format DESCRIPTION
This format is also known as the TI-Tagged or TI-SDSMAC format. This format allows binary files to be uploaded and downloaded between two computer systems, typically between a computer system (such as a PC, Macintosh, or workstation) and an emulator or evaluation board for microcontrollers and microprocessors. The Lines Unlike many other object formats, the lines themselves are not especially significant. The format consits of a number of tagged fields, and lines are composed of a series of these fields. Tag Description ------------------------------------- * Data byte. : End of file. 0 File header (optional). 7 Checksum. 8 Dummy checksum (ignored). 9 Address. B Data word. F End of data record. K Program identifier (optional). Data Byte +--+---+---+ |B | n | n | One byte of data. The nn is 8-bit big-endian hexadecimal. +--+---+---+ End of File +--+------+ |: | CRLF | The end of data is indicated by this tag. The end of line sequence+(LF-on+Unix systems, CRLF on PCs) follows this tag. File Header +--+--------+----------+ |0 | length | filename | The optional start-of-file record begins with a tag character-('0')-and-a-12-character file header. The first four characters are the byte count of the file data. The remaining 8 characters are the name of the file and may be any ASCII characters, blank padded. Checksum +--+---+---+---+---+ |7 | n | n | n | n | The checksum is the 2s complement sum of the 8-bit ASCII values+of-characters,-beginning with the first tag character and ending with the checksum tag character (7). The nnnn is 16-bit big-endian hexadecimal. Dummy Checksum +--+---+---+---+---+ |8 | n | n | n | n | The checksum is the 2s complement sum of the 8-bit ASCII values-of-characters, beginning with the first tag character and ending with the checksum tag character (8). The nnnn is 16-bit big-endian hexadecimal. Address +--+---+---+---+---+ |9 | n | n | n | n | Addresses may be given for any data byte, but none is mandatory.--The-file-begins at 0000 if no address is given before the first data field. The nnnn is 16-bit big-endian hexadecimal. Data Word +--+---+---+---+---+ |B | a | a | b | b | Two bytes of data. The aa and bb are each 8-bit big-endian hexadecimal.---+---+ End of Record +--+------+ |F | CRLF | The end of line sequence (LF on Unix systems, CRLF on PCs) is escaped-using this tag. The checksum is reset to zero at this point. Program Identifier +--+---+---+---+---+------+ |K | n | n | n | n | text | The program identifier can contain a brief description-of+the+program,-or-can be empty (i.e. the text portion is optional). The nnnn length (hex) of the field includes the `K', the length and the text; it is at least 5. Size Multiplier In general, binary data will expand in sized by approximately 2.9 times when represented with this format. EXAMPLE
Here is an example TI-Tagged file. It contains the data "Hello, World[rq] to be loaded at address 0x0100. K000590080B4865B6C6CB6F2CB2057B6F72B6C64*0A7F648F : and here is another example from the reference below 00050 7FDD4F 90000BFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFF7F400F 90010BFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFF7F3FFF 90020BFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFF7F3FEF 90030BFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFF7F3FDF 90040BFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFFBFFFF7F3FCF : SEE ALSO
http://www.dataio.com/pdf/Manuals/Unifamily/981-0014-016.pdf (page 6-33) COPYRIGHT
srec_cat version 1.58 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Peter Miller The srec_cat program comes with ABSOLUTELY NO WARRANTY; for details use the 'srec_cat -VERSion License' command. This is free software and you are welcome to redistribute it under certain conditions; for details use the 'srec_cat -VERSion License' command. AUTHOR
Peter Miller E-Mail: pmiller@opensource.org.au //* WWW: http://miller.emu.id.au/pmiller/ Reference Manual SRecord srec_ti_tagged(5)
All times are GMT -4. The time now is 10:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy