number of chars

Thread Tools Search this Thread
# 1  
number of chars

I am curious why the below returns 4 instead of 3
wc -c <<<aaa

a=aaa;echo ${#a}

returns 3.
How to get 3 using here -string operator in the above scenario

# 2  
What you're asking cannot be done, as far as I know. bash (I'm assuming that's what you're using) appends a newline at the end of the here-string, even when the command is terminated with a semicolon. I presume this is to maintain compatibility between a here-string and a here-document of identical content.

Actually, I wouldn't be surprised if the here-string is implemented with a here-document.


Last edited by alister; 07-04-2012 at 03:41 PM..
# 3  
Further to allister, if the here string in your Shell (whatever that is) had not appended a linefeed (thereby making the 4th character) the "wc" command would have seen nothing because it expects correctly formatted text files.

If you needed the answer three, you would have to subtract one from the result to eliminate count for the linefeed character.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Mathematics
Difficulty: Hard
In Topology, the complement of an open set is a closed set.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to split data with a delimiter having chars and special chars

Hi Team, I have a file a1.txt with data as follows. dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><! The delimiter string: <SelectStatement modified='1' type='string'><! dlm="<SelectStatement modified='1' type='string'><! The above command is... (7 Replies)
Discussion started by: kmanivan82
7 Replies

2. UNIX for Advanced & Expert Users

Inserting delimiter after a specific number of chars

Hello guys, I have a problem where I need to add a delimiter, that can be | for example, after each 28000 chars. The problem is that sometimes 1 row, which should contain 28000 chars is split in 2, so I want to put the delimiter after each 28000 so I will know the end of each row. Please... (2 Replies)
Discussion started by: Diogo R Jesus
2 Replies

3. Shell Programming and Scripting

Help in duplicated chars in password

i have code to generate passwords but the issue is the duplicated chars so can any one help and give me function to check and verify if there is any duplicated chars as also the script uses capitals and small letters and numbers only many thx guys (4 Replies)
Discussion started by: Suicide_king
4 Replies

4. UNIX for Dummies Questions & Answers

Find all chars before .

Howdy, I need a command which will find all of the characters in a line before the first . I am using Korn Thank you (3 Replies)
Discussion started by: jgrosecl
3 Replies

5. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

6. UNIX for Dummies Questions & Answers

Using SED to get n chars after given value from file

Hello, my name is Marc, I'm a linux starter :) and I hope you specialists can help me solving this issue. I have a file containing a lot of data. Somewhere in this file, there's a string called "Faultdump", directly followed by 64 chars of HEX data. I need to get the HEX part. I accomplished... (12 Replies)
Discussion started by: Kally
12 Replies

7. Shell Programming and Scripting

How to convert C source from 8bit chars to 16bit chars?

I was using the following bash command inside the emacs compile command to search C++ source code: grep -inr --include='*.h' --include='*.cpp' '"' * | sed "/include/d" | sed "/_T/d" | sed '/^ *\/\//d' | sed '/extern/d' Emacs will then position me in the correct file and at the correct line... (0 Replies)
Discussion started by: siegfried
0 Replies

8. Shell Programming and Scripting

cut last 4 chars

hi i wanted to cut last 4 chars from a text file Input A-B-C-V-15-0115 A-BL-CLE-T-VALUE-0125 M-T-L-G-0115 AT-PR-PE-CCT-0135 Output 0115 0125 0115 0135 I tried cut -f - -d "-" (thinking cut -f 5- -d"-" gives 5 ot end of line so only - should give last but floped) (5 Replies)
Discussion started by: pbsrinivas
5 Replies

9. Shell Programming and Scripting

Retreive string between two chars

I want to write a shell script in order to retreive some data from a log file that i have written into. The string that i want to get is the number 2849 (that is located between | | ). To explain further, this is the result i get after running "grep LOGIN filename.log" but i need to get the... (25 Replies)
Discussion started by: danland
25 Replies

10. Shell Programming and Scripting

replace chars,

:rolleyes: Hi, I want to replace the particular text in the middle of the line. Ex. In the line 40-50 wanted to replace the char as 'x' (7 Replies)
Discussion started by: Jairaj
7 Replies

Featured Tech Videos