Sponsored Content
Operating Systems Solaris Calculate the length and add some string infront Post 302167280 by vino on Thursday 14th of February 2008 01:32:40 AM
Old 02-14-2008
Quote:
Originally Posted by salaathi
Hi all,

I have file having 4 coulmn like

9246309198,406655682,400009246309198
9246309198,9246309198,400009246309198
9246309198,9246309198,400009246309198
9246309198,9246309198,400009246309198
9246309198,406655682,400009246309198
9246309198,9246309198,400009246309198

I want to valid the 2nd column if the length of the 2nd column is 9 digit i want add astring X beginning of the 2nd column.Which will give me the Output like.


9246309198,X406655682,400009246309198
9246309198,9246309198,400009246309198
9246309198,9246309198,400009246309198
9246309198,9246309198,400009246309198
9246309198,X406655682,400009246309198
9246309198,9246309198,400009246309198

Dears Is it possible?.
Code:
sed -e "s/^\([^,]*,\)\([0-9]\{9\}\),/\1X\2,/g" input.txt

or
Code:
sed -e "s/^\([^,]*,\)\([^,]\{9\}\),/\1X\2,/g"

 

6 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

3. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

4. Shell Programming and Scripting

How can use the perl or other command line to calculate the length of the character?

For example, if I have the file whose content are: >HWI-EAS382_30FC7AAXX:7:1:927:1368 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA >HWI-EAS382_30FC7AAXX:7:1:924:1373 ACGAACTTTAAAGCACCTCTTGGCTCGTATGCCGTC I want my output calculate the total length of nucleotide. So my output should look like this:... (1 Reply)
Discussion started by: patrick chia
1 Replies

5. Shell Programming and Scripting

Calculate the length of the each variable and matches to the desired value

My script is currently doing two function and I want to add one more as pre the question. echo -en "Enter the logmsg=" read logmsg logmsg1=${logmsg%%|*}; logmsg_len2=$(echo ${logmsg} | awk '{print $2}'); logmsg_suffix="|"; Char() { #echo $logmsg1 echo $logmsg1 | tr ',' '\n' | awk... (4 Replies)
Discussion started by: rohit22hamirpur
4 Replies

6. Shell Programming and Scripting

Add string based on character length

Good day, I am a newbie here and thanks for accepting me I have a task to modify input data where my input data looks like 123|34567|CHINE 1|23|INDIA 34512|21|USA 104|901|INDIASee that my input has two columns with different character length but max length is 5 and minimum length is 0 which... (1 Reply)
Discussion started by: fastlearner
1 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 05:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy