aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/cut.c10
-rwxr-xr-xtestsuite/cut.tests21
2 files changed, 28 insertions, 3 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c
index f4cf5401b..3abebe7ad 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -243,6 +243,16 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
243 start = next; 243 start = next;
244 continue; 244 continue;
245 } 245 }
246 /* -F N-M preserves intermediate delimiters: */
247 //printf "1 2 3 4 5 6 7\n" | toybox cut -O: -F2,4-6,7
248 //2:4 5 6:7
249 if (opt_REGEX && dcount <= cut_list[cl_pos].endpos)
250 continue;
251// NB: toybox does the above for -f too, but it's a compatibility bug:
252//printf "1 2 3 4 5 6 7 8\n" | toybox cut -d' ' -O: -f2,4-6,7
253//2:4 5 6:7 // WRONG!
254//printf "1 2 3 4 5 6 7 8\n" | cut -d' ' --output-delimiter=: -f2,4-6,7
255//2:4:5:6:7 // GNU coreutils 9.1
246 } 256 }
247#if ENABLE_FEATURE_CUT_REGEX 257#if ENABLE_FEATURE_CUT_REGEX
248 if (end != start || !opt_REGEX) 258 if (end != start || !opt_REGEX)
diff --git a/testsuite/cut.tests b/testsuite/cut.tests
index 52d05fde3..e57b028ac 100755
--- a/testsuite/cut.tests
+++ b/testsuite/cut.tests
@@ -104,6 +104,19 @@ Weather forecast for tonight : dark.
104Apple: you can buy better, but you can't pay more. 104Apple: you can buy better, but you can't pay more.
105Subcalifragilisticexpialidocious. 105Subcalifragilisticexpialidocious.
106Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy." 106Auntie Em: Hate you, hate Kansas. Took the dog. Dorothy."
107
108optional FEATURE_CUT_REGEX LONG_OPTS
109testing "cut -F preserves intermediate delimiters" \
110 "cut --output-delimiter=: -F2,4-6,7" \
111 "2:4 5 6:7\n" \
112 "" "1 2 3 4\t\t5 6 7 8\n"
113SKIP=
114
115optional LONG_OPTS
116testing "cut -f does not preserve intermediate delimiters" \
117 "cut --output-delimiter=: -d' ' -f2,4-6,7" \
118 "2:4:5:6:7\n" \
119 "" "1 2 3 4 5 6 7 8\n"
107SKIP= 120SKIP=
108 121
109testing "cut empty field" "cut -d ':' -f 1-3" \ 122testing "cut empty field" "cut -d ':' -f 1-3" \
@@ -124,23 +137,25 @@ testing "cut -dNEWLINE" \
124 "2\n4\n6\n7\n" \ 137 "2\n4\n6\n7\n" \
125 "" "1\n2\n3\n4\n5\n6\n7" 138 "" "1\n2\n3\n4\n5\n6\n7"
126 139
140optional LONG_OPTS
127testing "cut -dNEWLINE --output-delimiter" \ 141testing "cut -dNEWLINE --output-delimiter" \
128 "cut -d' 142 "cut -d'
129' -O@@ -f4,2,6-8" \ 143' --output-delimiter=@@ -f4,2,6-8" \
130 "2@@4@@6@@7\n" \ 144 "2@@4@@6@@7\n" \
131 "" "1\n2\n3\n4\n5\n6\n7" 145 "" "1\n2\n3\n4\n5\n6\n7"
132 146
133testing "cut -dNEWLINE --output-delimiter 2" \ 147testing "cut -dNEWLINE --output-delimiter 2" \
134 "cut -d' 148 "cut -d'
135' -O@@ -f4,2,6-8" \ 149' --output-delimiter=@@ -f4,2,6-8" \
136 "2@@4@@6@@7\n" \ 150 "2@@4@@6@@7\n" \
137 "" "1\n2\n3\n4\n5\n6\n7\n" 151 "" "1\n2\n3\n4\n5\n6\n7\n"
138 152
139testing "cut -dNEWLINE --output-delimiter EMPTY_INPUT" \ 153testing "cut -dNEWLINE --output-delimiter EMPTY_INPUT" \
140 "cut -d' 154 "cut -d'
141' -O@@ -f4,2,6-8" \ 155' --output-delimiter=@@ -f4,2,6-8" \
142 "" \ 156 "" \
143 "" "" 157 "" ""
158SKIP=
144 159
145# This seems to work as if delimiter is never found. 160# This seems to work as if delimiter is never found.
146# We test here that -d '' does *not* operate as if there was no -d 161# We test here that -d '' does *not* operate as if there was no -d