Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

11 votes
4 answers
10714 views
What is wrong with using "\t" to grep for tab-separated values?
I have a .tsv file (values separated by tabs) with four values. So each line should have only three tabs and some text around each tab like this: value value2 value3 value4 But it looks that some lines are broken (there is more than three tabs). I need to find out these lines. --- I came up with fol...
I have a .tsv file (values separated by tabs) with four values. So each line should have only three tabs and some text around each tab like this: value value2 value3 value4 But it looks that some lines are broken (there is more than three tabs). I need to find out these lines. --- I came up with following grep pattern. grep -v "^[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+$" My thinking: - first ^ matches the beggining - [^\t]+ matches more than one "no tab character" - \t matches single tab character - $ matches end And than I just put it into right order with correct number of times. That should match correct lines. So I reverted it by -v option to get the wrong lines. But with the -v option it matches any line in the file and also some random text I tried that don't have any tabs inside. **What is my mistake please?** EDIT: I am using debian and bash.
TGar (307 rep)
Aug 16, 2022, 11:47 AM • Last activity: Jun 27, 2025, 08:47 AM
7 votes
5 answers
1448 views
A shell tool to “tablify” input data containing ANSI escape codes
I have input containing ANSI color codes that I'd like to tablify. I want the output to remain colored, so the tablified output should maintain the ANSI color codes. Hence, naively stripping them away does not meet my requirements. For example, for this input, \033[0;32;1mgreen_apple\033[0m 1 100 or...
I have input containing ANSI color codes that I'd like to tablify. I want the output to remain colored, so the tablified output should maintain the ANSI color codes. Hence, naively stripping them away does not meet my requirements. For example, for this input, \033[0;32;1mgreen_apple\033[0m 1 100 orange 20 19 pineapple 1000 87 avocado 4 30 The output I expect would be similar to green_apple 1 100 orange 20 19 pineapple 1000 87 avocado 4 30 In the above output, "green_apple" should be colored according to the color codes from the input i.e. green. I'd like to know how this can be accomplished. I've tried column, but it doesn't handle ANSI codes. The output of echo '\033[0;32;1mgreen_apple\033[0m 1 100 orange 20 19 pineapple 1000 87 avocado 4 30' | column -t is unfortunately green_apple 1 100 orange 20 19 pineapple 1000 87 avocado 4 30 Notice the non-tablification.
Jimmy Dean (81 rep)
Mar 24, 2014, 07:56 AM • Last activity: Feb 19, 2024, 06:25 PM
1 votes
1 answers
99 views
Expand tabs in file with utf8 characters
I use `expand` to expand tabs to spaces. For `utf8` files `expand` doesn't work correctly. E.g. in `ć\ta` tab is expanded to 6 spaces while in `a\ta` to 7 spaces. How do I make it work for `utf8` files?
I use expand to expand tabs to spaces. For utf8 files expand doesn't work correctly. E.g. in ć\ta tab is expanded to 6 spaces while in a\ta to 7 spaces. How do I make it work for utf8 files?
Marcin Król (253 rep)
Jun 6, 2023, 04:09 PM • Last activity: Jun 6, 2023, 08:18 PM
51 votes
7 answers
35840 views
command to layout tab separated list nicely
Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance var1 var2 var3 var_with_long_name_which_ruins_alignment var2 var3 Is there an easy way to render them aligned? var1 var2 var3 var_with_long_name_which_ruins_alignment var2 var3
Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance var1 var2 var3 var_with_long_name_which_ruins_alignment var2 var3 Is there an easy way to render them aligned? var1 var2 var3 var_with_long_name_which_ruins_alignment var2 var3
Elazar Leibovich (3321 rep)
Feb 20, 2011, 08:45 AM • Last activity: Oct 17, 2022, 06:02 PM
0 votes
1 answers
308 views
Kate replaces text instead of indenting when typing Tab on selected lines
I tried to change all the indentation settings to fix another problem yesterday, but now I have the following problem and I don't know which setting causes it. If I select lines and type Tab, I would expect the selected lines to be indented. Instead, the selection is replaced with a tabulation. For...
I tried to change all the indentation settings to fix another problem yesterday, but now I have the following problem and I don't know which setting causes it. If I select lines and type Tab, I would expect the selected lines to be indented. Instead, the selection is replaced with a tabulation. For example, I start with: aa bb cc Then I select a part (what's between [ and ] is the selected part): aa b[b c]c Then I press Tab (---> represents a tabulation), I expect this: aa --->bb --->cc But I get this instead: aa b--->c How can I revert this behaviour? I'm using Kate 21.12.3.
optical (137 rep)
Mar 17, 2022, 03:55 PM • Last activity: Mar 17, 2022, 06:24 PM
10 votes
2 answers
6353 views
How do I make Kate indent with spaces on Python files but use tabs for text files and other files?
My goal is to set Kate up to work properly on Python files but to use different settings (tabs not spaces) on other documents. I'm sure others are doing this, but I can't figure out a convenient solution. I appreciate any advice. Kate has settings for indentation here: 1. Click the Settings menu 2....
My goal is to set Kate up to work properly on Python files but to use different settings (tabs not spaces) on other documents. I'm sure others are doing this, but I can't figure out a convenient solution. I appreciate any advice. Kate has settings for indentation here: 1. Click the Settings menu 2. Click "Configure - Kate" 3. On the right expand "Editor" 4. Click "Indentation" One option is "Default indentation mode". One choice for that setting is Python. However, I cannot find where to set (or even display) the options used for the Python choice. Furthermore, it is not clear what is the interaction between "Default indentation mode" and the explicit settings for indentation on that page. Does one override the other?
MountainX (18888 rep)
Jul 25, 2013, 05:48 AM • Last activity: Mar 17, 2022, 03:35 PM
0 votes
0 answers
96 views
How to prevent tabulated outputs of functons being messed up when using 'watch' over ssh?
While ssh-ing into my server I want to be able to monitor for activity over certain port using `netstat`. Instead of running it manually I want to automate it with `watch`. While the command (`sudo netstat -apon | grep 44002`) running by itself gives the right output tcp 0 0 127.0.0.1:44002 0.0.0.0:...
While ssh-ing into my server I want to be able to monitor for activity over certain port using netstat. Instead of running it manually I want to automate it with watch. While the command (sudo netstat -apon | grep 44002) running by itself gives the right output tcp 0 0 127.0.0.1:44002 0.0.0.0:* LISTEN 1750/sshd: mainuser off (0.00/0/0) tcp6 0 0 ::1:44002 :::* LISTEN 1750/sshd: mainuser off (0.00/0/0) when combined with watch the output gets garbled looking roughly like: tcp 0 0.0.0.0:* LISTEN 1 c2-user off (0.00/0/0) tcp6 c2-user off (0.00/0/0) 0 ::1:44002 I suspect this has something to do with the witdh of the terminal not being handled properly. How can I fix this?
KubaFYI (113 rep)
Dec 12, 2019, 12:00 PM
0 votes
1 answers
541 views
How to search for all tabs between two quotation marks with grep / egrep
I'm looking for all tabs between two quotation marks with grep / egrep in a bash. I tried grep -r . -e "\".*\t.*\"" grep -r . -e "\".*\\t.*\"" grep -r . -e "\".*\\\\t.*\"" grep -r . -e '\".*\t.*\"' grep -r . -e '\".*\\t.*\"' grep -r . -e '".*\t.*"' grep -r . -e '".*\\t.*"' But I don't get the desire...
I'm looking for all tabs between two quotation marks with grep / egrep in a bash. I tried grep -r . -e "\".*\t.*\"" grep -r . -e "\".*\\t.*\"" grep -r . -e "\".*\\\\t.*\"" grep -r . -e '\".*\t.*\"' grep -r . -e '\".*\\t.*\"' grep -r . -e '".*\t.*"' grep -r . -e '".*\\t.*"' But I don't get the desired result. Following greps yield all line with a \t: grep -r . -e "\".*\\\\t.*\"" grep -r . -e '\".*\\t.*\"' grep -r . -e '".*\\t.*"' Following greps yield all line with a t: grep -r . -e "\".*\t.*\"" grep -r . -e "\".*\\t.*\"" grep -r . -e '".*\t.*"' grep -r . -e '\".*\t.*\"' But none of these searches for a real tabulator. What I'm doing wrong?
Thomas Sablik (132 rep)
Jul 24, 2019, 08:39 AM • Last activity: Jul 24, 2019, 10:16 AM
0 votes
1 answers
4913 views
What '\t' mean with 'tab' delimiter with 'cut' in BASH
In this command : cut -f2 -d$'\t' (`'\t'`) what is it mean ? i saw it another question, i got the idea about "tab" delimiter but still want to know `'\t'` shortcut or sign or command for something [How to define 'tab' delimiter with 'cut' in BASH][1] [1]: https://unix.stackexchange.com/questions/353...
In this command : cut -f2 -d$'\t' ('\t') what is it mean ? i saw it another question, i got the idea about "tab" delimiter but still want to know '\t' shortcut or sign or command for something How to define 'tab' delimiter with 'cut' in BASH
MAX LEARNING (11 rep)
May 21, 2019, 07:30 PM • Last activity: Jun 30, 2019, 07:27 AM
0 votes
2 answers
3175 views
removing all tabs in sqlplus
I can resolve this problem, but I don't understand why it happens. My task is: (in ksh) - 1st step: Query a number from a DB with sqlplus, - 2nd step: Format some text for a mail, - 3rd step: send a mail with these. This is a part of my code: psnr() { sqlplus -s USR/PASS@PROD $MAILTMP if I want to u...
I can resolve this problem, but I don't understand why it happens. My task is: (in ksh) - 1st step: Query a number from a DB with sqlplus, - 2nd step: Format some text for a mail, - 3rd step: send a mail with these. This is a part of my code: psnr() { sqlplus -s USR/PASS@PROD $MAILTMP if I want to use this variable *MAILTMP* I must use tr -d '\040\011' what I found here, in stackexchange, 'cause the result without tr will be this: od -c mailtmp.17872.txt 0000000 T o d a y ' s r e s u l t i 0000020 s : \t 1 2 3 4 5 0000040 6 7 \n 0000043 That tab '\t' is what I don't understand: where does it come from, from sqlplus? Possibly DB specificity? (I checked in TOAD, both coloumns are number(18). Maybe the function in ksh have some special features?
Apex (3 rep)
Nov 4, 2015, 04:18 PM • Last activity: Jul 14, 2017, 05:28 PM
3 votes
1 answers
352 views
Can I force column to emit whitespaces instead of tabs?
I'd like to tabularize a file with the `column` command: $ column -c 60 file.txt The output is nice on the screen, but unusable for my purposes because the items are seperated by tabs. for further processing, I need them as whitespace. Of course, I cannot just replace one tab with one space because...
I'd like to tabularize a file with the column command: $ column -c 60 file.txt The output is nice on the screen, but unusable for my purposes because the items are seperated by tabs. for further processing, I need them as whitespace. Of course, I cannot just replace one tab with one space because this would destroy the left-alignment of the 2nd, 3rd etc column.
René Nyffenegger (2321 rep)
Feb 16, 2017, 06:05 AM • Last activity: Jul 9, 2017, 09:54 PM
4 votes
1 answers
744 views
How does unexpand command really work?
I've already read some explananations about unexpand, but either I don't understand, or is not working as expected. Let's consider the following example: [root@hope log]# echo "A12345678B" | tr '[1-8]' ' ' | unexpand -a A B [root@hope log]# echo "A12345678B" | tr '[1-8]' ' ' | unexpand -a | od -ta 0...
I've already read some explananations about unexpand, but either I don't understand, or is not working as expected. Let's consider the following example: [root@hope log]# echo "A12345678B" | tr '[1-8]' ' ' | unexpand -a A B [root@hope log]# echo "A12345678B" | tr '[1-8]' ' ' | unexpand -a | od -ta 0000000 A ht sp B nl 0000005 [root@hope log]# echo "A12345678B12345678C" | tr '[1-8]' ' ' | unexpand -a | od -ta 0000000 A ht sp B ht sp sp C nl 0000011 [root@hope log]# echo "12345678" | tr '[1-8]' ' ' | unexpand -a | od -ta 0000000 ht nl 0000002 I see that it replaces 8 blanks with one tab, but it appends one more space each time it appears some non-blank character. Using bash-4.3.42-3.fc23.x86_64 and coreutils-8.24-6.fc23.x86_64 Please could you explain this behaviour?
sebelk (4669 rep)
Mar 14, 2016, 09:53 PM • Last activity: Mar 14, 2016, 10:51 PM
48 votes
3 answers
10669 views
set tab width for less output
Is it possible for `less` output to set the tab width to a number `X` as it is for [cat][1]? [1]: https://stackoverflow.com/a/10782861/3739455
Is it possible for less output to set the tab width to a number X as it is for cat ?
polym (11052 rep)
Jul 30, 2014, 02:24 PM • Last activity: Jan 21, 2016, 12:39 AM
13 votes
5 answers
5438 views
What command(s) will feed a tab-delimited text file and cut each line to 80 characters?
I've got multiple-line text files of (sometimes) tab-delimited data. I'd like to output the file so I can glance over it - so I'd like to only see the first 80 characters of each line (I designed the text file to put the important stuff first on each line). I'd thought I could use cat to read each l...
I've got multiple-line text files of (sometimes) tab-delimited data. I'd like to output the file so I can glance over it - so I'd like to only see the first 80 characters of each line (I designed the text file to put the important stuff first on each line). I'd thought I could use cat to read each line of the file, and send each line to the next command in a pipe: cat tabfile | cut -c -80 But that seemed broken. I tried monkeying around, and grep appeared to work - but then I found out that, no it didn't (not every line in the file had 80+ characters) - it appears tabs are counted as single characters by cut. I tried: cat tabfile | tr \t \040 | cut -c -80 Even though that would mangle my data a bit, by eliminating the white-space readability. But that didn't work. Neither did: cat tabfile | tr \011 \040 | cut -c -80 Maybe I'm using tr wrong? I've had trouble with tr before, wanting to remove multiple spaces (appears the version of tr that I have access to on this machine has an -s option for squeezing down multiple characters - I may need to play with it more) I'm sure if I messed around I could use perl, awk or sed, or something to do this. However, I'd like a solution that uses (POSIX?) regular commands, so that it's as portable as possible. If I do end up using tr, I'd probably eventually try turning tabs into characters, maybe do a calculation, cut on the calculation, and then turn those characters back into tabs for the output. It doesn't need to be a single line / entered directly on the command line - a script is fine. --- More info on tab-files: I use tab to break fields, because someday I may want to import data into some other program. So I tend to have only one tab between pieces of content. But I also use tabs to align things with vertical columns, to aid in readability when looking at the plain text file. Which means for some pieces of text I pad the end of the content with spaces until I get to where the tab will work in lining up the next field with the ones above and below it.
DarkTurquoise           #00CED1	        Seas, Skies, Rowboats   Nature
MediumSpringGreen       #00FA9A         Useful for trees        Magic  
Lime                    #00FF00         Only for use on spring chickens and fru$
user3082 (1031 rep)
Dec 25, 2014, 07:56 AM • Last activity: Dec 25, 2014, 08:11 PM
3 votes
1 answers
426 views
How to set default tabs only for cat?
I prefer to set `tabs 4` however this may have some side effects, such as [for example `ls` out put may look not properly aligned](https://unix.stackexchange.com/a/111838/9760). **How might I configure the terminal / cat to use four spaces for tabs for cat only?** Should I just alias / wrap `cat` to...
I prefer to set tabs 4 however this may have some side effects, such as [for example ls out put may look not properly aligned](https://unix.stackexchange.com/a/111838/9760) . **How might I configure the terminal / cat to use four spaces for tabs for cat only?** Should I just alias / wrap cat to something that sets tabs 4, runs /bin/cat, then sets it back? My thinking is that this route is less preferable since in fact I would like this behaviour for less, diff, and other utilities.
dotancohen (16493 rep)
Jul 8, 2014, 12:22 PM • Last activity: Jul 9, 2014, 07:03 PM
2 votes
2 answers
10409 views
How to configure Kate to always use 2 spaces for tabulation?
By default Kate inserts 2 spaces on Tab press but switches to real tabs starting from the fourth Tab level. Can I disable this and use spaces always, regardless to the depth? I want this because I use Kate to code Scala, and using space pairs instead of tabs is a convention there.
By default Kate inserts 2 spaces on Tab press but switches to real tabs starting from the fourth Tab level. Can I disable this and use spaces always, regardless to the depth? I want this because I use Kate to code Scala, and using space pairs instead of tabs is a convention there.
Ivan (18358 rep)
Nov 5, 2010, 02:27 AM • Last activity: May 9, 2014, 02:21 AM
Showing page 1 of 16 total questions