Score:0

bash, display only in case output has count of n characters

ss flag

how can I display content of output which has only count of n characters in second col divided by ,? For example, grep only line which content 4 characters in second col.

Input.

a,123
b,223
c,1234
d,323
e,2234

Output.

c,1234
e,2234

Is some easy way to do this, for example by cut and sed, or for loop must be used?

Thanks.

Score:1
hr flag

Some options:

grep ',....$' file

grep ',.\{4\}$' file

sed -n '/,....$/p' file

sed '/,....$/!d' file

sed -n '/,.\{4\}$/p' file

sed '/,.\{4\}$/!d' file

grep -E ',.{4}$' file

sed -En '/,.{4}$/p' file

sed -E '/,.{4}$/!d' file

gawk -F, 'length($2) == 4' file

perl -F, -lne 'print if length($F[1]) == 4' file
genderbee avatar
ss flag
Thanks, and in case I need check **3rd** col divided by `,`?
genderbee avatar
ss flag
OK, I know now. Thank you very much for answer.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.