Sponsored Content
Top Forums Shell Programming and Scripting Conditional replacement of columns in a text file Post 302884733 by magnus29 on Tuesday 21st of January 2014 01:44:22 PM
Old 01-21-2014
Conditional replacement of columns in a text file

Hello scriping expert friends,

I have 2 requirements on replacing fields of text files:

I have lot of data with contents like below:
Code:
[FEN "1rr2b1k/3q1P1p/p4p2/1pp1p2B/2PpP2P/1P1P4/P3Q3/R1B3RK w - - 0 33"]
[FEN "2bqk1r1/p4p2/1p2pQp1/1n1pP1Bp/7P/3P2N1/P4PP1/6K1 w - - 0 3"]
[FEN "2q3kr/6r1/1p2N3/5p2/1P1p4/6R1/7P/6K1 w - - 0 3"]
[FEN "2r2r1k/pp1q1p1p/3bpn2/5P2/1P6/P3P3/1B3P1P/R3K1R1 w Q - 0 2"]

Requirement-1:

The digit after 0 should always be changed to 1
Code:
[FEN "1rr2b1k/3q1P1p/p4p2/1pp1p2B/2PpP2P/1P1P4/P3Q3/R1B3RK w - - 0 1"]
[FEN "2bqk1r1/p4p2/1p2pQp1/1n1pP1Bp/7P/3P2N1/P4PP1/6K1 w - - 0 1"]
[FEN "2q3kr/6r1/1p2N3/5p2/1P1p4/6R1/7P/6K1 w - - 0 1"]
[FEN "2r2r1k/pp1q1p1p/3bpn2/5P2/1P6/P3P3/1B3P1P/R3K1R1 w Q - 0 1"]

Requirement-2:

if 3rd column value is "w" (just before hyphens) then I should make it to "b" and vice-versa.
Code:
[FEN "1rr2b1k/3q1P1p/p4p2/1pp1p2B/2PpP2P/1P1P4/P3Q3/R1B3RK b - - 0 33"]
[FEN "2bqk1r1/p4p2/1p2pQp1/1n1pP1Bp/7P/3P2N1/P4PP1/6K1 b - - 0 3"]
[FEN "2q3kr/6r1/1p2N3/5p2/1P1p4/6R1/7P/6K1 b - - 0 3"]
[FEN "2r2r1k/pp1q1p1p/3bpn2/5P2/1P6/P3P3/1B3P1P/R3K1R1 b Q - 0 2"]

I could get them done but with some poor scripting. I read value of each column and compare and echoing to another file but I guess awk/sed would do so much effecient. I have no idea how to use awk.Smilie

Please provide me 2 different commands separately as sometimes I may have to do only one of them.

TIA
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacement of text in a file

Hi , I have some data in my file(properties.txt) like this. # agent.properties agent.dmp.Location= agent.name= I need to relpace the agent.dmp.location with agent.dmp.Location = /opt/VRTS/vxvm I am using the follwing to replace the string AGENT_NAME=snmp... (2 Replies)
Discussion started by: raghu.amilineni
2 Replies

2. Shell Programming and Scripting

HELP Need in SED/PERL conditional line replacement

Hi , I need some help on perl/sed conditional replacement The situation is like below . I have a file contents like below . AAA|BBB|CCC|DDD AAA|BCF|CCC|HHH AAA|BVF|JJJ|KKK Here in the above file . I know my second column value (taking "|" as my delimited ) Basically I have to... (3 Replies)
Discussion started by: robin.r888
3 Replies

3. Shell Programming and Scripting

Conditional tab replacement sed/awk

Hi I am struggling to find a solutions to this problem: I have a directory full of files and I wish to: read each line of each file and if any one line in those files is longer than 72 characters I want to replace any tab characters with a space character. Ive been... (3 Replies)
Discussion started by: benackland
3 Replies

4. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

5. Shell Programming and Scripting

conditional replacement

Hi all, I need a bash, sed, awk script or one liner to do the following task: This is the format of a text file: 2010-06-11 20:01 902656 HOP-W-100412-1.doc 2010-11-05 18:01 364447 NEX-W-101104-1 2010-07-06 10:01 64512 Cerintele 2010-07-06 10:01 599420 content 2010-07-19 14:01 1785344... (7 Replies)
Discussion started by: supervazi
7 Replies

6. Shell Programming and Scripting

Conditional replacement of a delimiter

Hello, I'm new to this forum but this seems like the place to ask this question. I have a pipe delimited data file with the fields except for the header being encased in double quotes. I found out that some of the fields have an trash pipe within the data itself. I'd like to conditionally... (4 Replies)
Discussion started by: samahs
4 Replies

7. UNIX for Dummies Questions & Answers

Removing columns from a text file that do not have any values in second and third columns

I have a text file that has three columns. But at the end of the text file, there are trailing lines that have missing second and third columns: 4 0.04972604 KLHL28 4 0.0497332 CSTB 4 0.04979822 AIF1 4 0.04983331 DECR2 4 0.04990344 KATNB1 4 4 4 4 How can I remove the trailing... (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Shell Programming and Scripting

How to concatenate 2-columns by 2 -columns for a text file?

Hello, I want to concatenate 2-columns by 2-columns separated by colon. How can I do so? For example, I have a text file containing 6 columns separated by tab. I want to concatenate column 1 and 2; column 3 and 4; column 5 and 6, respectively, and put a colon in between. input file: 1 0 0 1... (10 Replies)
Discussion started by: huiyee1
10 Replies

9. Shell Programming and Scripting

Conditional replacement in CSV files

Hello, I have many CSV files with variable number of rows and columns. Sample of few problematic CSV files. ,,Price,Price,Price,Price,Price,Price,Price,Price,Price,Qty Date,Sl,AAA,BBB,CCC,DDD,EEE,FFF,GGG,HHH,PriQueue,%busy 30/07/2014,1,AAA,BBB,CCC,DDD,EEE,FFF,GGG,HHH,NA,0... (8 Replies)
Discussion started by: reddyr
8 Replies

10. Shell Programming and Scripting

Multiple Replacement in a Text File in one operation (sed/awk) ?

Hi all, Saying we have two files: 1. A "Reference File" whose content is "Variable Name": "Variable Value" 2. A "Model File" whose content is a model program in which I want to substitute "VariableName" with their respective value to produce a third file "Program File" which would be a... (4 Replies)
Discussion started by: dae
4 Replies
IRSEND(1)								FSF								 IRSEND(1)

NAME
irsend - basic LIRC program to send infra-red commands SYNOPSIS
irsend [options] DIRECTIVE REMOTE CODE [CODE...] DESCRIPTION
Asks the lircd daemon to send one or more CIR (Consumer Infra-Red) commands. This is intended for remote control of electronic devices such as TV boxes, HiFi sets, etc. DIRECTIVE can be: SEND_ONCE - send CODE [CODE ...] once SEND_START - start repeating CODE SEND_STOP - stop repeating CODE LIST - list configured remote items SET_TRANSMITTERS - set transmitters NUM [NUM ...] SIMULATE - simulate IR event REMOTE is the name of a remote, as described in the lircd configuration file. CODE is the name of a remote control key of REMOTE, as it appears in the lircd configuration file. NUM is the transmitter number of the hardware device. For the LIST DIRECTIVE, REMOTE and/or CODE can be empty: LIST "" "" - list all configured remote names LIST REMOTE "" - list all codes of REMOTE LIST REMOTE CODE - list only CODE of REMOTE The SIMULATE command only works if it has been explicitly enabled in lircd. -h --help display usage summary -v --version display version -d --device use given lircd socket [/var/run/lirc/lircd] -a --address=host[:port] connect to lircd at this address -# --count=n send command n times EXAMPLES
irsend LIST DenonTuner "" irsend SEND_ONCE DenonTuner PROG-SCAN irsend SEND_ONCE OnkyoAmpli VOL-UP VOL-UP VOL-UP VOL-UP irsend SEND_START OnkyoAmpli VOL-DOWN ; sleep 3 irsend SEND_STOP OnkyoAmpli VOL-DOWN irsend SET_TRANSMITTERS 1 irsend SET_TRANSMITTERS 1 3 4 irsend SIMULATE "0000000000000476 00 OK TECHNISAT_ST3004S" FILES
/etc/lirc/lircd.conf Default lircd configuration file. It should contain all the remotes, their infra-red codes and the corresponding timing and wave- form details. DIAGNOSTICS
If lircd is not running (or /var/run/lirc/lircd lacks write permissions) irsend aborts with the following diagnostics: "irsend: could not connect to socket" "irsend: Connection refused" (or "Permission denied"). SEE ALSO
The documentation for lirc is maintained as html pages. They are located under html/ in the documentation directory. lircd(8), mode2(1), smode2(1), xmode2(1), irrecord(1), irw(1), http://www.lirc.org. irsend 0.8.7pre1 May 2010 IRSEND(1)
All times are GMT -4. The time now is 06:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy