Lines Matching refs:line

22     Stream editor. Apply one or more editing SCRIPTs to each line of input
32 -z Use \0 rather than \n as the input line separator
40 apply only to the specified line(s). Commands without an address apply to
41 every line. Addresses are of the form:
45 The ADDRESS may be a decimal line number (starting at 1), a /regular
47 matches the last line of input. (In -s or -i mode this matches the last
48 line of each file, otherwise just the last line of the last file.) A single
49 address matches one line, a pair of comma separated addresses match
62 Sed mostly operates on individual lines one at a time. It reads each line,
64 reading the next line. Sed can remember one additional line in a separate
65 buffer (using the h, H, g, G, and x commands), and can read the next line
80 d Delete this line and move on to the next one
83 D Delete one line of input and restart command SCRIPT (same as "d"
86 g Get remembered line (overwriting current line)
88 G Get remembered line (appending to current line)
90 h Remember this line (overwriting remembered line)
92 H Remember this line (appending to remembered line, if any)
94 l Print line, escaping \abfrtv (but not newline), octal escaping other
96 backslash, and appending $ to actual end of line.
98 n Print default output and read next line, replacing current line
99 (If no next line available, quit processing script)
101 N Append next line of input to this line, separated by a newline
102 (This advances the line counter for address matching and "=", if no
103 next line available quit processing script without default output)
105 p Print this line
107 P Print this line up to first newline (from "N")
111 x Exchange this line with remembered line (overwrite in both directions)
113 = Print the current line number (followed by a newline)
117 the next line (for which leading whitespace is not skipped), and also
120 a [text] Append text to output before attempting to read next line
124 c [text] Delete line, output text at end of matching address range
130 next line.
140 a backslash at the end of the line appends the next line.
147 p Print the line if match was found and replaced
148 w [file] Write (append) line to file if match replaced
151 this line since last test (replacing with same text counts)
155 w [file] Write (append) line to file
163 # Comment, ignore rest of this line of SCRIPT
167 printf escapes in text, line continuations, semicolons after all commands,
169 continuations for [abc], \; to end [abc] argument before end of line.
199 long lmatch[2]; // line number of match
207 // Write out line with potential embedded NUL, handling eol/noeol
208 static int emit(char *line, long len, int eol)
210 int l, old = line[len];
214 if (eol) line[len++] = '\n';
216 l = writeall(TT.fdout, line, len);
217 if (eol) line[len-1] = old;
254 // Apply pattern to line from input file
262 char *line = TT.nextline;
270 // Grab next line for deferred processing (EOF detection: we get a NULL
271 // pline at EOF to flush last line). Note that only end of _last_ input
281 if (!line || !len) return;
282 if (line[len-1] == '\n') line[--len] = eol++;
293 // Have we got a line or regex matching range for this rule?
305 // regex match end includes matching line, so defer deactivation
306 if (line && !regexec0(rm, line, len, 0, 0, 0)) miss = 1;
316 if (line && !regexec0(rm, line, len, 0, 0, 0))
346 // A deleted line can still update line match state for later commands
347 if (!line) {
374 free(line);
375 line = 0;
378 free(line);
379 line = 0;
383 str = line;
384 while ((str-line)<len) if (*(str++) == '\n') break;
385 len -= str - line;
386 memmove(line, str, len);
388 // if "delete" blanks line, disable further processing
391 free(line);
392 line = 0;
394 line[len] = 0;
399 free(line);
400 line = xstrdup(TT.remember);
403 line = xrealloc(line, len+TT.rememberlen+2);
404 line[len++] = '\n';
405 memcpy(line+len, TT.remember, TT.rememberlen);
406 line[len += TT.rememberlen] = 0;
409 TT.remember = xstrdup(line);
414 memcpy(TT.remember+TT.rememberlen, line, len);
435 x = stridx("\\\a\b\f\r\t\v", line[i]);
439 } else if (line[i] >= ' ') toybuf[off++] = line[i];
440 else off += sprintf(toybuf+off, "\\%03o", line[i]);
449 // Can't just grab next line because we could have multiple N and
453 extend_string(&line, TT.nextline, len, -TT.nextlen);
455 TT.nextline = line;
457 line = 0;
463 char *l = (c=='P') ? strchr(line, '\n') : 0;
465 if (emit(line, l ? l-line : len, eol)) break;
473 if (c=='Q') line = 0;
477 char *rline = line, *new = command->arg2 + (char *)command, *l2 = 0;
483 // Loop finding match in remaining line (up to remaining len)
484 while (!regexec0(reg, rline, len-(rline-line), 10, match, mflags)) {
490 if (rline-line == len) break;
563 // If we made any changes, finish off l2 and swap it for line
566 mlen = len-(rline-line);
569 free(line);
570 line = l2;
575 if (command->sflags & 4) emit(line, len, eol);
596 if (emit(line, len, eol))
605 TT.remember = line;
606 line = str;
617 j = stridx(from, line[i]);
618 if (j != -1) line[i] = to[j];
628 if (line && !FLAG(n)) emit(line, len, eol);
645 else emit(line, 0, 0);
649 free(line);
751 char *line, *reg, c, *errstart;
754 line = errstart = pline ? *pline : "";
755 if (len && line[len-1]=='\n') line[--len] = 0;
757 // Append this line to previous multiline command? (hit indicates type.)
758 // During parsing "hit" stores data about line continuations, but in
776 // Loop through commands in this line.
782 // If there's no more data on this line, return.
784 while (isspace(*line) || *line == ';') line++;
785 if (*line == '#') while (*line && *line != '\n') line++;
788 if (!*line) return;
792 errstart = line;
799 if (*line == ',') line++;
802 if (i && *line == '+' && isdigit(line[1])) {
803 line++;
804 command->lmatch[i] = -2-strtol(line, &line, 0);
805 } else if (isdigit(*line)) command->lmatch[i] = strtol(line, &line, 0);
806 else if (*line == '$') {
808 line++;
809 } else if (*line == '/' || *line == '\\') {
810 char *s = line;
812 if (!(s = unescape_delimited_string(&line, 0))) goto error;
823 while (isspace(*line)) line++;
824 if (!*line) break;
826 if (*line == '!') {
828 line++;
830 while (isspace(*line)) line++;
831 if (!*line) break;
833 c = command->c = *(line++);
850 // line continuations use arg1 (back at the start of the function),
856 if (!(TT.remember = unescape_delimited_string(&line, &delim)))
865 end = line;
877 reg = extend_string((void *)&command, line, reg-(char *)command,end-line);
878 line = end;
879 // line continuation? (note: '\n' can't be a valid delim).
880 if (*line == command->hit) command->hit = 0;
882 if (!*line) continue;
884 line++;
894 for (line++; *line; line++) {
897 if (isspace(*line) && *line != '\n') continue;
899 if (0 <= (l = stridx("igp", *line))) command->sflags |= 1<<l;
900 else if (!(command->sflags>>3) && 0<(l = strtol(line, &line, 10))) {
902 line--;
913 if (*line == 'w') {
914 line++;
927 while (isspace(*line)) line++;
928 if (!*line) goto error;
929 for (cc = line; *cc; cc++) if (*cc == '\\' && cc[1] == ';') break;
932 fd = xcreate(line, O_WRONLY|O_CREAT|O_TRUNC, 0644);
936 command = xrealloc(command, command->w+(cc-line)+6);
942 memcpy(reg, line, delim);
946 line = cc;
947 if (delim) line += 2;
952 if (!(s = unescape_delimited_string(&line, &delim))) goto error;
958 if (!(s = unescape_delimited_string(&line, &delim))) goto error;
966 while (isspace(*line) && *line != '\n') line++;
974 if (!(end = strcspn(line, strchr(":btTqQ", c) ? "}; \t\r\n\v\f" : "\n"))){
981 for (i = 0; i<end && isdigit(line[i]); i++);
983 line += i;
997 reg = extend_string((void *)&command, line, reg - (char *)command, end);
999 // Recopy data to remove escape sequences and handle line continuation.
1003 if ((*reg++ = *line++)=='\\') {
1005 // escape at end of line: resume if -e escaped literal newline,
1006 // else request callback and resume with next line
1009 if (*line) {
1010 line++;
1016 if (!(reg[-1] = unescape(*line))) reg[-1] = *line;
1017 line++;
1021 } else line += end;
1028 error_exit("bad pattern '%s'@%ld (%c)", errstart, line-errstart+1L, *line);