invalid syntax para impresion de lineas
Publicado por Pablo Suarez (4 intervenciones) el 21/11/2022 17:07:20
###########tengo este script de python para imprimir la primera linea del archivo con terminacion .gbk y las lineas con el caracter "product"
# input text file
inputFile = "c00617_NODE_61...region001.gbk"
# Enter the string
givenString = "product"
## the first line of the file
import linecache
particular_line1 = linecache.getline(inputFile, 1)
# Opening the given file in read-only mode
with open(inputFile, 'r') as filedata:
# Traverse in each line of the file
for line in filedata:
# Checking whether the given string is found in the line data
if givenString in line:
# Print the line, if the given string is found in the current line
print(particular_line1 + line)
#### el anterior script corre bien sin embargo cuando lo pongo el string de una sola linea para meterlo en loop de bash me marca error
python -c "import linecache; inputFile = 'c00617_NODE_61...region001.gbk'; givenString = 'product'; particular_line1 = linecache.getline(inputFile, 1); with open(inputFile, 'r') as filedata:; for line in filedata:; if givenString in line:; print(particular_line1 + line)"
### Me sale sintaxis invalida, no se que moverle, el error empieza desde que quiero abrir el archivo modo lectura (with open ...)
# input text file
inputFile = "c00617_NODE_61...region001.gbk"
# Enter the string
givenString = "product"
## the first line of the file
import linecache
particular_line1 = linecache.getline(inputFile, 1)
# Opening the given file in read-only mode
with open(inputFile, 'r') as filedata:
# Traverse in each line of the file
for line in filedata:
# Checking whether the given string is found in the line data
if givenString in line:
# Print the line, if the given string is found in the current line
print(particular_line1 + line)
#### el anterior script corre bien sin embargo cuando lo pongo el string de una sola linea para meterlo en loop de bash me marca error
python -c "import linecache; inputFile = 'c00617_NODE_61...region001.gbk'; givenString = 'product'; particular_line1 = linecache.getline(inputFile, 1); with open(inputFile, 'r') as filedata:; for line in filedata:; if givenString in line:; print(particular_line1 + line)"
### Me sale sintaxis invalida, no se que moverle, el error empieza desde que quiero abrir el archivo modo lectura (with open ...)
Valora esta pregunta


0