Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.

[Solved] Length of each string

Thread Tools Search this Thread
# 1  
[Solved] Length of each string


I have a file which has sequences which look like this

qwwerrtyuiopasdfghjmnbvfklzxerbvcwghjjkoowwqerrtggbddqsdfgaqwcxzakjtyugfsdefrtgyhujiknbbbbcdcdcxsxsx zxzxcvcfcdcg


Is there a way I could find the length of each string?

For an example:
(If I need to count length of STRING 1 ,I need to begin from

and stop at " > " of string2)

Could anyone advise?

Last edited by Scrutinizer; 12-24-2013 at 10:27 PM.. Reason: code tags
# 2  
You have a carriage control (newline character) after >String1. This will not count that character.

awk 'NR%2==1 {keep=$0; next}
        NR%2==0 {print keep, length(keep $0)}  ' inputfile

# 3  
Doesnt the awk command you mentioned count the length per line?
I was wondering if there is a way to count length of a particular string.

eg: say for string2
it would count from

qwwerrtyuiopasdfghjmnbvfklzxerbvcwghjjkoowwqerrtggbddqsdfgaqwcxzakjtyugfsdefrtgyhujiknbbbbcdcdcxsxsx zxzxcvcfcdcg

till the start of string3? ( ie. till '>' of string 3)

I hope I am not confusing.

Last edited by Don Cragun; 12-25-2013 at 01:52 AM.. Reason: Add CODE tags
# 4  
Please use code tags for posting code fragments or data samples.

I would suggest you to post expected output as well to avoid any confusion.
# 5  
Try (untested)
awk '{print length ($0)}' RS=">" ORS=">" file

This User Gave Thanks to RudiC For This Post:

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
[Solved] Listing files starting with p or f and with the exact length of 3 characters
Hello, I need some help. How can I list files starting with p or f and with the exact length of 3 characters?... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
[SOLVED] String length in kornshell
In the kornshell you can get the length of a string with $ x=abc $ print ${#x} 3 If the current locale is a multibyte locale, like de_AT.UTF-8, you get the length of the string in bytes, not characters: $ x=für $ print ${#x} 4 Is there an easy way to get the length of a...... Shell Programming and Scripting
Shell Programming and Scripting
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...... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
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...... Shell Programming and Scripting
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...... Shell Programming and Scripting
Shell Programming and Scripting

Featured Tech Videos