Sponsored Content
Full Discussion: Swapping strings in a file
Top Forums Shell Programming and Scripting Swapping strings in a file Post 302388348 by xoops on Wednesday 20th of January 2010 05:13:27 AM
Old 01-20-2010
try this

Code:
 
$ cat inf
"DEF", "678", "ABC", "GHI", "KLM", ...."123",
"345", XYZ", "MNO", "PQR",

$ cat inf | sed 's/ABC/TMP/g;s/XYZ/ABC/g;'| sed 's/TMP/XYZ/g'
"DEF", "678", "XYZ", "GHI", "KLM", ...."123",
"345", ABC", "MNO", "PQR",

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Swapping of fields in a file

Hi I have afile with 15fields,say f1,f2....f15 delimited on comma. How can i swap the f1,f15 fields using unix shell commands or any script? Thanks (3 Replies)
Discussion started by: ksailesh
3 Replies

2. Shell Programming and Scripting

Swapping IP Addresses In A File With Those From Another File

Hello, I'm looking for a way to change the IP addresses in a large host file with those of matching hostnames in another file. For example, I have a file with file1 contains lines like: 192.168.0.55 hostname hostname.network.lan 192.168.0.52 junkhost junkhost.network.dev... (2 Replies)
Discussion started by: PointyWombat
2 Replies

3. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

4. Shell Programming and Scripting

Extract two strings from a file and create a new file with these strings

I have the following lines in a log file. It would be great if some one can help me to create a new file with the just entries in the below format. 66.150.161.195 HPSAC=Z05 66.150.161.196 HPSAC=A05 That is just extract the IP address and the string DPSAC=its value 66.150.161.195 -... (1 Reply)
Discussion started by: Tuxidow
1 Replies

5. UNIX for Dummies Questions & Answers

Swapping the columns of a text file for a subset of rows

Hi, I'd like to swap the columns 1 and 2 of a space-delimited text file but only for the first 1000 rows. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Swapping of fields in file

Hi Friends , I have file1.txt 1|b|46|123|47673|348738 2|c|63|124|7346|4783 3|y|45|125|5555|78789 output should swap the 4th field to the first field. output 123|1|b|46|47673|348738 124|2|c|63|7346|4783 125|3|y|45|5555|78789 (3 Replies)
Discussion started by: i150371485
3 Replies

7. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

8. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

9. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

10. UNIX for Beginners Questions & Answers

(g)awk: Matching strings from one file in another file between two strings

Hello all, I can get close to what I am looking for but cannot seem to hit it exactly and was wondering if I could get your help. I have the following sample from textfile with many thousands of lines: File 1 PS001,001 HLK PS002,004 L<G PS004,002 XNN PS004,006 BVX PS004,006 ZBX=... (7 Replies)
Discussion started by: jvoot
7 Replies
ct_telnet(3erl) 					     Erlang Module Definition						   ct_telnet(3erl)

NAME
ct_telnet - Common Test specific layer on top of telnet client ct_telnet_client.erl. DESCRIPTION
Common Test specific layer on top of telnet client ct_telnet_client.erl Use this module to set up telnet connections, send commands and perform string matching on the result. See the unix_telnet manual page for information about how to use ct_telnet, and configure connections, specifically for unix hosts. The following default values are defined in ct_telnet: Connection timeout = 10 sec (time to wait for connection) Command timeout = 10 sec (time to wait for a command to return) Max no of reconnection attempts = 3 Reconnection interval = 5 sek (time to wait in between reconnection attempts) Keep alive = true (will send NOP to the server every 10 sec if connection is idle) These parameters can be altered by the user with the following configuration term: {telnet_settings, [{connect_timeout,Millisec}, {command_timeout,Millisec}, {reconnection_attempts,N}, {reconnection_interval,Millisec}, {keep_alive,Bool}]}. Millisec = integer(), N = integer() Enter the telnet_settings term in a configuration file included in the test and ct_telnet will retrieve the information automatically. Note that keep_alive may be specified per connection if required. See unix_telnet for details. DATA TYPES
connection() = handle() | {target_name() (see module ct), connection_type()} | target_name() (see module ct) : connection_type() = telnet | ts1 | ts2 : handle() = handle() (see module ct_gen_conn) : Handle for a specific telnet connection. prompt_regexp() = string() : A regular expression which matches all possible prompts for a specific type of target. The regexp must not have any groups i.e. when matching, re:run/3 shall return a list with one single element. EXPORTS
close(Connection) -> ok | {error, Reason} Types Connection = connection() (see module ct_telnet) Close the telnet connection and stop the process managing it. A connection may be associated with a target name and/or a handle. If Connection has no associated target name, it may only be closed with the handle value (see the open/4 function). cmd(Connection, Cmd) -> {ok, Data} | {error, Reason} Equivalent to cmd(Connection, Cmd, DefaultTimeout) . cmd(Connection, Cmd, Timeout) -> term() cmdf(Connection, CmdFormat, Args) -> {ok, Data} | {error, Reason} Equivalent to cmdf(Connection, CmdFormat, Args, DefaultTimeout) . cmdf(Connection, CmdFormat, Args, Timeout) -> term() cont_log(Str, Args) -> term() end_log() -> term() expect(Connection, Patterns) -> term() Equivalent to expect(Connections, Patterns, []) . expect(Connection, Patterns, Opts) -> {ok, Match} | {ok, MatchList, HaltReason} | {error, Reason} Types Connection = connection() (see module ct_telnet) Patterns = Pattern | [Pattern] Pattern = string() | {Tag, string()} | prompt | {prompt, Prompt} Prompt = string() Tag = term() Opts = [Opt] Opt = {timeout, Timeout} | repeat | {repeat, N} | sequence | {halt, HaltPatterns} | ignore_prompt Timeout = integer() N = integer() HaltPatterns = Patterns MatchList = [Match] Match = RxMatch | {Tag, RxMatch} | {prompt, Prompt} RxMatch = [string()] HaltReason = done | Match Reason = timeout | {prompt, Prompt} Get data from telnet and wait for the expected pattern. Pattern can be a POSIX regular expression. If more than one pattern is given, the function returns when the first match is found. RxMatch is a list of matched strings. It looks like this: [FullMatch, SubMatch1, SubMatch2, ...] where FullMatch is the string matched by the whole regular expression and SubMatchN is the string that matched subexpression no N . Subexpressions are denoted with '(' ')' in the regular expression If a Tag is given, the returned Match will also include the matched Tag . Else, only RxMatch is returned. The function will always return when a prompt is found, unless the ignore_prompt options is used. The timeout option indicates that the function shall return if the telnet client is idle (i.e. if no data is received) for more than Timeout milliseconds. Default timeout is 10 seconds. The repeat option indicates that the pattern(s) shall be matched multiple times. If N is given, the pattern(s) will be matched N times, and the function will return with HaltReason = done . The sequence option indicates that all patterns shall be matched in a sequence. A match will not be concluded untill all patterns are matched. Both repeat and sequence can be interrupted by one or more HaltPatterns . When sequence or repeat is used, there will always be a MatchList returned, i.e. a list of Match instead of only one Match . There will also be a HaltReason returned. Examples: expect(Connection,[{abc,"ABC"},{xyz,"XYZ"}], [sequence,{halt,[{nnn,"NNN"}]}]). will try to match "ABC" first and then "XYZ", but if "NNN" appears the function will return {error,{nnn,["NNN"]}} . If both "ABC" and "XYZ" are matched, the function will return {ok,[AbcMatch,XyzMatch]} . expect(Connection,[{abc,"ABC"},{xyz,"XYZ"}], [{repeat,2},{halt,[{nnn,"NNN"}]}]). will try to match "ABC" or "XYZ" twice. If "NNN" appears the function will return with HaltReason = {nnn,["NNN"]} . The repeat and sequence options can be combined in order to match a sequence multiple times. get_data(Connection) -> {ok, Data} | {error, Reason} Types Connection = connection() (see module ct_telnet) Data = [string()] Get all data which has been received by the telnet client since last command was sent. open(Name) -> {ok, Handle} | {error, Reason} Equivalent to open(Name, telnet) . open(Name, ConnType) -> {ok, Handle} | {error, Reason} Types Name = target_name() ConnType = connection_type() (see module ct_telnet) Handle = handle() (see module ct_telnet) Open a telnet connection to the specified target host. open(KeyOrName, ConnType, TargetMod) -> {ok, Handle} | {error, Reason} Equivalent to open(KeyOrName, ConnType, TargetMod, []) . open(KeyOrName, ConnType, TargetMod, Extra) -> {ok, Handle} | {error, Reason} Types KeyOrName = Key | Name Key = atom() Name = target_name() (see module ct) ConnType = connection_type() TargetMod = atom() Extra = term() Handle = handle() Open a telnet connection to the specified target host. The target data must exist in a configuration file. The connection may be associated with either Name and/or the returned Handle . To allocate a name for the target, use ct:require/2 in a test case, or use a require statement in the suite info function ( suite/0 ), or in a test case info function. If you want the connection to be associated with Handle only (in case you need to open multiple connections to a host for example), simply use Key , the configuration variable name, to specify the target. Note that a connection that has no associated target name can only be closed with the handle value. TargetMod is a module which exports the functions connect(Ip,Port,KeepAlive,Extra) and get_prompt_regexp() for the given TargetType (e.g. unix_telnet ). send(Connection, Cmd) -> ok | {error, Reason} Types Connection = connection() (see module ct_telnet) Cmd = string() Send a telnet command and return immediately. The resulting output from the command can be read with get_data/1 or expect/2/3 . sendf(Connection, CmdFormat, Args) -> ok | {error, Reason} Types Connection = connection() (see module ct_telnet) CmdFormat = string() Args = list() Send a telnet command and return immediately (uses a format string and a list of arguments to build the command). SEE ALSO
unix_telnet AUTHORS
<> common_test 1.5.3 ct_telnet(3erl)
All times are GMT -4. The time now is 06:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy